个人工具

UbuntuHelp:SoundTroubleshooting

来自Ubuntu中文

Wikibot讨论 | 贡献2008年5月9日 (五) 19:21的版本

跳转至: 导航, 搜索

Upgrading from an earlier release of Ubuntu to Hardy you may end up missing kernel sound modules

if "find /lib/modules/`uname -r` | grep snd" returns no results, then your upgrade/dist-upgrade missed the linux-ubuntu-modules package, you need to install it and reboot:

sudo aptitude install linux-ubuntu-modules-`uname -r` linux-generic

Background / Notes / Warnings

I can't guarantee if these instructions will work for everybody, and this is definitely a work in progress. But if these instructions can at least help one person out, I'll be happy. If you cannot use hear anything, and you have just installed Ubuntu, then it could very possibly be a bug. It could be something as simple as not detecting your hardware the first time or evidence of a deeper problem. As fun as it is to find workarounds and fixes on your own or with help, Ubuntu developers need your feedback to see what is not working for you. That's right ladies and gentlemen, they would really really like it if you would file bug reports on http://launchpad.net under the Ubuntu distribution. Note: To make it absolutely clear, when I say 'Ubuntu', I mean Ubuntu AND Kubuntu AND Xubuntu (for people who find this confusing - just accept it and don't feel bad - I and probably a whole lot others got confused when we started out). Important syntax note: ALSA modules are denoted by the prefix 'snd' followed by the dash ' - ', followed by the module name (i.e. 'via82xx'). So the full name might be something like snd-via82xx. However, in some cases you will see an underscore ' _ ' instead of the dash. This is OK, do not let it confuse you. When mentioning module names (to install them or communicate their names to others) only use the dash ' - '.

General Help

Start here if you have no idea why sound is not playing

  • Go to a shell and type: aplay -l
  • Success - You will get a list of the all the soundcards installed on your system. Your sound just might be muted. See alsamixer section.
  • Failure - You will get a message like aplay: device_list:221: no soundcard found... Move on to step 2.
  • Type this into the shell: lspci -v
  • Success - At this point, you should see your sound card listed. This is a positive sign because it means that Ubuntu is detecting the presence of your soundcard, but the drivers are not installed/running. Leave your shell running since you will need it.
  • Failure - If it is not listed, then there are a few things that you can do.
  • If your soundcard is an onboard sound card, then it might be disabled in the system's BIOS. You will have to reboot and hit the key that lets you enter into the BIOS (usually Delete, F2, or F8).
  • If your soundcard is not onboard, make sure that it is properly seated in the PCI slot. If your card is working under Windows then this is not a problem.
  • Check to see if the ALSA driver for your sound card exists. Go to http://www.alsa-project.org/main/index.php/Matrix:Main and search for your sound card (chipset) manufacturer.
  • Success - You will have found the driver for your soundcard's chipset.
  • Failure - You will have not found the driver for your soundcard chipset. (at the moment I cannot help you, but stay tuned!)
  • Now go back to the shell and type sudo modprobe snd-[NAME OF YOUR SOUNDCARD'S DRIVER]. For example, my driver is a via82xx so I would type, sudo modprobe snd-via82xx.
  • Success - A success here means that your soundcard was installed, but it was not being loaded. Now you have loaded it for the current session.
  • To load it for all sessions (you will probably want to do this) you will have to edit /etc/modules (I think this is the file, I'll check once I get to my Dapper PC).
  • Type this into the shell sudo nano /etc/modules
  • Add only the name of the module to be loaded at the end of the file. In my case, the via82xx module gave me sound so I added "snd-via82xx" to the end of the file.(iii) Make sure that you have all channels unmuted in alsamixer.
  • See the alsamixer section
  • Play media using your favorite media player. Set your audio engine to alsa. In some cases, you have to configure your audio engine within another (media engine) like in Kaffiene in Kubuntu. If you hear sound, hurray!
  • One final step. Go onto Saving Sound Settings
  • Failure - You have two options
  • Move on to Getting the ALSA drivers from a *fresh* kernel. This step is easier and is recommended to users who might have been tinkering with their sound settings and want to revert back to the way it was just after installing Ubuntu (without reinstalling Ubuntu of course )
  • Move on to ALSA driver Compilation, if you have not done so already. If you have, please post a new thread with your problem.

Getting the ALSA drivers from a *fresh* kernel

Sometimes, sound might be configured correctly, but for some reason or another (tinkering) it stops working. One way to go back to the old setup is to reinstall Ubuntu. However, this step is actually quite unnecessary since you are reinstalling everything because of one thing. A faster way, is to just remove the problematic packages and reinstall them cleanly.

  • Remove these packages sudo apt-get --purge remove linux-sound-base alsa-base alsa-utils
  • Reinstall those same packages sudo apt-get install linux-sound-base alsa-base alsa-utils
  • VERY IMPORTANT NOTE - Ubuntu (GNOME): users have reported that packages 'gdm' and 'ubuntu-desktop' are removed after removing the linux-sound-base packages. If this happens, then do the following sudo apt-get install gdm ubuntu-desktop
  • VERY IMPORTANT NOTE - Xubuntu (XFCE): users have reported that packages 'gdm' and 'ubuntu-desktop' are removed after removing the linux-sound-base. If this happens, then do the following sudo apt-get install gdm xubuntu-desktop
  • Reboot
  • At this point, try using aplay -l you should get your soundcard listed.
  • Success - Your soundcard is detected. Go onto the Using alsamixer section, then try playing something on your music or media player.
  • Failure - Your card was not detected. You should try compiling your driver, so go onto ALSA drive Compilation.

Now you may ask "I already had the packages, so why did I go through the trouble of removing them, then installing them". The answer lies in the --purge option which removes all the extra information that accumulated from tinkering and upgrading. After doing a purge then install, the packages are unpackaged as if it they are brand new.

ALSA driver Compilation

  • If you are here, then either your soundcard driver could not be loaded with modprobe, or you want to compile the drivers yourself from scratch. Good luck to you!
  • There are two main ways the sources of alsa-drivers are made available to you. One is through the apt-get system. Using this system would be the recommended system since most of the heavy lifting is done for you.
  • The other way, is getting the latest drivers from alsa-project.org. This page has the latest drivers available, which you might want to fix problems with. However, these have not been tested with Ubuntu and therefore should be used with caution.

Using alsa-source

Open up a shell: (note: module-assistant is optional, it will compile the package for you)

  • Type sudo apt-get install build-essential linux-headers-$(uname -r) module-assistant alsa-source
  • Type sudo dpkg-reconfigure alsa-source
  • You now have a big blue dialog box (left and right keys to choose 'Yes' and 'No', Enter key proceed). Answer yes (for ISA-PNP - recommended by package maintainers), then yes again (for debugging - recommended by package maintainers).
  • Now you must pick which driver you want to install. Use space to select and deselect modules, and up and down to navigate.
  • From General Help step 3, you should know the name of your driver. Deselect 'all' (the * will go away), and select your driver. In my case, I deselected 'all' then selected 'via82xx'. Hit Enter. Almost home free!
  • If you chose module-assistant sudo module-assistant a-i alsa-source. If the progress bar reaches 100% with no errors, you will have installed the drivers successfully. Resume this guide from General Help step 4.
  • If you did not choose module-assistant - Remember the name of your soundcard driver (eg. via82xx) and use it in place of <insert driver> below.
cd /usr/src
sudo tar xjvf alsa-driver.tar.bz2
cd alsa-driver<insert alsa version, if necessary>
sudo ./configure  --with-kernel=/usr/src/linux-headers-$(uname -r) --with-cards=<insert driver> --with-oss=yes
sudo make
sudo make install
  • If you get no error messages, you will have installed the drivers successfully.
    • Success - Resume this guide from General Help step 4.
    • Failure - Start a new thread in this thread of the forum. Paste the error message that you get and state that you were following instructions on this page.

Using drivers from alsa-project

update I now recommend using the stable version 1.0.12 The alsa-project route is very similar to the alsa-source route without the module-assistant. First you would have to get the alsa-driver tar from alsa-project then pretty much do configure, make and make install again. However, I do recommend that you make a specific directory when you compile something from source. Remember the name of your soundcard driver and use it in place of the blue text below.

mkdir src
cd src
mkdir alsa
cd alsa
sudo apt-get install build-essential linux-headers-$(uname -r)
wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.12.tar.bz2
tar -xvjf alsa-driver-1.0.12.tar.bz2
cd alsa-driver-1.0.12
sudo ./configure  --with-kernel=/usr/src/linux-headers-$(uname -r) --with-cards=<enter driver name here e.g. via82xx> --with-oss=yes
sudo make
sudo make install

If you get no errors from doing the above then you have successfully compiled alsa-drivers from source. Resume this guide from General Help step 4.

Using alsamixer

  • Type this into a shell alsamixer

You will now see what appears to be a graphical equalizer. It is more like ten different volume controls in the sample place.

  • To navigate around:
    • Left and Right Arrow Keys - Move left and right (if you move long enough in one direction you will get back to where you started - you will not fall off the screen )
    • Up and Down Arrow Keys - Increase and decrease volume respectively.
    • Letter M Key - Mutes/unmutes. If a channel is unmuted, then there is a green box underneath the volume slider. If the channel is muted, the box is grey.

Saving Sound Settings

Do this step to ensure that your alsamixer settings are reloaded with each boot. First make sure you have your settings just the way you like them in alsamixer. Then do sudo alsactl store 0 or if this is your nth sound card (where n is the number of soundcards in your computer) replace 0 with n-1. Many thanks to xpix for trying this out.

Loading a working sound configuration

If you can find someone with similar HW as yours and has working sound, you could take their settings and try them on your HW.

  1. Get a working /var/lib/alsa/asound.state from someone who has similar hardware
  2. Save it as /tmp/asound.state
  3. alsactl -F -f /tmp/asound.state restore

Getting more than one application to use the soundcard at the same time

  • You might want to play a game and listen to music on your favorite music player at the same time. To do this successfully, you will have to use ALSA since it supports this feature the best. On all the music players I know of, you can configure the sound engine, to any module that is available.
  • The setting is usually found under something like Tools >>> Configure >>> Player Engines.
  • For games, it is a bit more tricky since there is not always a way to configure the player engine directly. Most games, however, do support the OSS. ALSA has an OSS module that allows OSS applications to use the ALSA driver.
  • To do this you will need the alsa-oss package sudo apt-get install alsa-oss
  • After doing this step, it is very easy to use alsa-oss. In the shell, you can type 'aoss' then the name of the program name you want to use with alsa-oss.

Configuring default soundcards / stopping soundcards from switching

Note: This section assumes that you have installed each soundcard properly.

  • In a shell, type cat /proc/asound/modules
  • This will give the the name and index of each soundcard you have currently. Make a note of the names, and decide which one you want to be the default card.
  • Now type sudo nano /etc/modprobe.d/alsa-base
  • At the very end of the file, add the following (assuming you have 3 cards with module names A, B and C and you want to have them in the order CAB)
options snd-C index=0
options snd-A index=1
options snd-B index=2

Getting MIDI To Work - *EXPERIMENTAL*

This section assumes you can successfully hear sound from your soundcard. First of all, make sure that you actually have a MIDI port on your soundcard. Most onboard soundcards do not have a MIDI port. Next, open up this file: sudo nano /etc/modprobe.d/alsa-base Then add this options line options <snd module name here i.e. snd-via82xx> mpu_port=0x330 OR if you already have a options line for this soundcard add mpu_port=0x330 to the line. The default MIDI port is 330. You should verify this number in your BIOS if you are not sure. If the number is not listed, it is most likely that the number is 330 (add the 0x for the file). If you get no errors, you have successfully installed your MIDI port. At the moment, I do not know if any further configuration is necessary.

Miscellaneous Tips and Tricks

Here are a few things that other people have dug up over the course of this guide. Not all tips are meant to work for all hardware (believe me hda-intel will probably have like a mini guide of it's own one day).

I wasn't getting any sound out of my Sony Vaio PCG-4B1L ...The crucial thing is to enable everything in alsamixer EXCEPT "external amplifier." (I had to turn off microphone too, to stop feedback).

  • Useff had a very annoying problem where he could get sound through alsa from one user, but not through is main account. http://www.ubuntuforums.org/showthread.php?p=1221754. He and I managed to fix the problem by making sure the main account was in the audio group in /etc/group (which he was) and deleting the .asoundrc file in the main account's /home directory.
  • Bo Rosén solved his ISA problem the following way. Thanks to FarEast for his help in the matter.

Thanks to [[http://ubuntuforums.org/showthread.php?t=127402]] this post I got soundblaster 16 isa working. In short add{{{snd-sb16{{{ to /etc/modules then create a new file: {{{gedit /etc/modprobe.d/sound and enter this line:

options snd-sb16 isapnp=0 port=0x220 irq=5 dma8=1 dma16=5
sudo update-modules
reboot}}}
  • webbca01 figured out how to get AC'97 work with the help of the second last post here and this post. Basically, if you have an intel8x0 module, you can get AC'97 working by sudo nano /etc/modprobe.d/alsa-base and adding this as the last line: "options snd-intel8x0 ac97_quirk=3"
  • scragar noticed that sometimes even if ubuntu is set to use a particular sound card it still attempts to use a default sound card that may or may not be set, in which case
sudo apt-get install asoundconf-gtk && asoundconf-gtk will allow you to quickly change your default sound card(you may also uninstall asoundconf-gtk afterwards, provided you select remove and not "completely remove", from synaptic, or purge from the command line).

Advanced Guides by other Ubuntuers

To Do:

Important - no particular order

  • Getting MIDI to work
  • Compiling alsa entirely (drivers, utils, oss, etc)
  • Getting line input to work if it does not already - for microphones, etc.
  • Getting SPDIF output to work if it does not already - for amplifiers, speakers with digital in.

On the backburner

  • Scripts for getting configuration that needs to be done in this post to be done automatically

Related

Getting keyboard multimedia keys to work - [MultimediaKeys] (I personally like the non-keytouch route - configuring xmodmap and then using gnome-keybindings or for KDE (System Settings >> Regional and Language Settings >> Keyboard Shortcuts). The xmodmap route also works for XFCE, but I do not how to configure XFCE application keybindings.

Posts / References /Credits

Hoary Sound Broke Problem with Azalia audio MultipleCards from alsa.opensrc.org Volume Control does not save my settings after reboot Every single sound problem error post I have read The Ubuntu community for being energetic, dynamic, and polite providers of help with Ubuntu Linux in all its flavours.

  1. title Debugging Sound Problems

Basic troubleshooting

Preliminary checks

  1. Is your sound system plugged in and switched on. I spent an hour trying to diagnose a sound issue when the problem was that I had switched off the speakers to answer a phone call and forgot that I had done so. :-(

Checking volume levels

  1. From command line: Open a terminal window and launch alsamixer then make sure sound is unmuted and that the volume is turned up. Unmute everything, sometimes a muted channel will be the problem, even if the description doesn't seem immediately relevant.
  2. From GUI: This can be done by running something like gnome-alsamixer from a terminal window or navigating to your your Volume Control. Again, at this point make sure sound is unmuted and that the volume is turned up. Unmute everything, sometimes a muted channel will be the problem, even if the description doesn't seem immediately relevant. Also check that your switches are set correctly - for instance that if you use the analog output the analog switch is set ON or that the digital or S/PDIF switch is set OFF. You can select which tracks/switches are visible in Volume Control (see above) under Edit->Preferences.
  • Note: These controls have equivalent functionality to alsamixer but with a graphical interface. Checking or unchecking devices in the these accomplishes the exact same thing as unmuting or muting devices, respectively, in alsamixer.
  • Starting with Ubuntu 7.04, the sound volume control is also accessible from Menu->Sound&Video->Volume Control. It may be hidden in your menus but can be shown by going to System > Preferences > Main Menu and under Applications > Sound&Video ticking Volume Control.

Checking sound device assignment

  1. Most sound applications output to card0 by default. In some cases, other audio devices (like a USB MIDI Keyboard) might be recognized as a soundcard and take card0, bumping your real soundcard to card1. To see which devices are connected to which cards, do the following:
  •  cat /proc/asound/cards
  1. You can manipulate the device number assignment by adding snd-usb-audio to /etc/modprobe.d/alsa-base . Next boot, the snd-usb-audio device will get index 1.
  •  options snd-usb-audio index=1

Checking permissions and resources

  1. Make sure that all users needing access to the Sound Device can "Use audio devices" in the "User Privileges" tab of users-admin (System->Administration->Users and Groups). You have to be part of the "audio" group to play sound.
  2. Test different "Sound Servers": Go to System > Preferences > Sound ("Multimedia Systems Selector" in earlier editions of Ubuntu). From there, you can test the different options. In some scenarios several different sound servers may be installed, and only one may work. This is probably the origin of the problem if you cannot play audio with xine or rhythmbox, but you can with xmms or helix/realplayer.
  3. If you application sounds works, but your system sounds does not (login, logout, error sounds...) try removing the .asoundrc* files from your own directory (e.g. with 'rm .asoundrc*'). It should make the system sounds work without a reboot.
  4. If you can get absolutely no sound and you have an onboard sound chip you can try to disable it in the BIOS. This solves the problem is some cases.
  5. If you have no sound and you have a regular sound card type "lsmod | grep snd" in the terminal and see if there is more than one card listed. It's possible that you have a motherboard sound chip that is interfering. Add it to the bottom of the blacklist file. For example, sudo nano /etc/modprobe.d/blacklist then add "blacklist snd_via82xx" to the bottom.

Reset mixer setting to default

If you have messed around with the mixer settings, and would like to reset back to the defaults, carry out the following steps. You can find out your sound module from the output of lsmod.

  1. Delete /var/lib/alsa/asound.state
  2. sudo rmmod <sound driver> e.g. sudo rmmod snd-hda-intel
  3. sudo modprobe <sound driver> e.g. sudo modprobe snd-hda-intel

This will reset asound.state to default values.

Reporting Sound Bugs

Please do not report problems on this page; use the normal support channels instead. See http://www.ubuntu.com/support If you feel you have encountered a software bug, please report the bug at https://launchpad.net/ubuntu/+filebug using your kernel version as the package. If you are uncertain of the kernel version that you have installed you can check by typing uname -a in a terminal. Also, be sure to include the following information to your report. Please be sure to add each file as a separate https://help.ubuntu.com/community/SoundTroubleshooting?action=AttachFile&do=get&target=

  1. Output of 'uname -a'
  •  uname -a > uname-a.log
  1. Output of 'sudo lspci -vvnn'
  •  sudo lspci -vvnn | tee lspci-vvnn.log
  1. Sound Information (see below for how to gather)

Automatic Sound Information Collection

This is the preferred method for gathering the appropriate sound information from you system. It's helps ensure that you gather the sound information correctly and completely. The following script gathers all required information in one: [1]. The script was written to aid the alsa developers, and also to help the people in #alsa to sort out sound issues. Please download and run the script as follows:

  1. Open a text editor.
  2. Copy the script contents and save it to a file named "aadebug"
  3. Give this file permission to execute by running
     chmod +x aadebug 
    
  4. run
     sudo ./aadebug | tee aadebug.log 
    
  5. aadebug.log will be generated. Attach this file to your bug report

Manual sound configuration collection

This is the information gathered from the automated sound information collection script. We highly recommend you use the automated script when gathering the sound information regarding your system. Manually collection of the information by hand is a tedious process and is more prone to user error.

  1. You can use aplay to get a list of soundcards configured by alsa
  •  $ aplay --list-devices

aplay: device_list:200: no soundcards found...

  1. The following commands can help to figure out what sound card (chip set) you have (Look for lines that contain 'Multimedia audio controller'). The actual {sub,}{vendor,device} IDs are important. That's how we track whether something exists as a quirk or needs to be added/modified.
  •  $ lspci -vvnn 

$ lspnp -v

  1. The following command lists the codecs involved. The output from this command is vital. Different codecs pushing the same driver (say, intel8x0, emu10k1, or hda-intel) exhibit a huge variation in errata.
  •  tail -2 /proc/asound/oss/sndstat
  1. It is imperative that you include the amixer output from your preferred (the one that's giving problems) audio device. The community has spent years documenting known mixer issues on http://alsa.opensrc.org/ (see drivers). For instance, many of the codecs driving cs46xx, emu10k1, and intel8x0 require multiple elements to be selected, unmuted, and raised to audible levels.
  •  amixer
  1. This script command (which is really just filtered cat /proc/asound/cards) lists the enumerated sound devices on your system.
  •  asoundconf list
  1. We need to know if you've modified any runtime configuration files that affect how alsa-lib interacts with your sound devices. The nonexistence of the above files is not a problem.
  •  cat /etc/asound.conf ~/.asoundrc*
  1. Many codecs and drivers, upon initialization, will spit something via printk() into the kernel ring buffer. Any diagnostic messages will appear in this output.
  •  dmesg
  1. Sound devices require resources. We need to see if those resources are properly assigned, the above command lists interrupts used.
  •  cat /proc/interrupts

Misc

A bit of useful information regarding manual installation of sound drivers as well as troubleshooting pulseaudio, flash, and sound mixing can be found here: https://help.ubuntu.com/community/DebuggingSoundProblemsMisc

Links

http://alsa.opensrc.org/index.php