Linux audio is powerful and flexible, and annoying as heck. When you have no sound it can be as simple as Alsamixer resetting everything to mute when you shutdown (Why? Who the heck knows) to problems caused by device conflicts, and our ever-popular friends* Java and Adobe Flash. Java and Flash need drama in their lives, so they break things to get attention.
If you have sound at startup, and then sound quits sometime during your session, the lsof (“list open files”) command will tell you if a process has hijacked your audio. This example shows Java locking up my audio and not letting it go. First take a look in /dev/snd:
$ ls -l /dev/snd
drwxr-xr-x 2 root root 60 2011-03-19 05:20 by-path
crw-rw—-+ 1 root audio 116, 7 2011-03-19 05:20 controlC0
crw-rw—-+ 1 root audio 116, 6 2011-03-19 05:20 hwC0D0
crw-rw—-+ 1 root audio 116, 5 2011-03-19 05:20 pcmC0D0c
crw-rw—-+ 1 root audio 116, 4 2011-03-19 08:26 pcmC0D0p
crw-rw—-+ 1 root audio 116, 3 2011-03-19 05:20 pcmC0D1p
crw-rw—-+ 1 root audio 116, 8 2011-03-19 05:20 seq
crw-rw—-+ 1 root audio 116, 2 2011-03-19 05:20 timer
Then run lsof on each one like this:
$ lsof /dev/snd/pcmC0D0p
When you get to the audio device that is in use it looks like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 2009 carla mem CHR 116,6 3665 /dev/snd/pcmC0D0p
java 2009 carla 27u CHR 116,6 0t0 3665 /dev/snd/pcmC0D0p
java 2009 carla 28u CHR 116,6 0t0 3665 /dev/snd/pcmC0D0p
java 2009 carla 29u CHR 116,6 0t0 3665 /dev/snd/pcmC0D0p
java 2009 carla 30u CHR 116,6 0t0 3665 /dev/snd/pcmC0D0p
Aha, I says to myself, Java strikes again. So what’s using Java?
$ ps ax | grep java
2009 ? Sl 0:22 /usr/local/moneydance/jre/bin/java -client -Dinstall4j.jvmDir=/usr/local/moneydance/jre -Dexe4j.moduleName=/usr/local/moneydance/Moneydance -Xmx400m -Di4j.vmov=true -Di4j.vmov=true -Di4j.vmov=true -Di4j.vmov=true -Di4j.vmov=true -classpath /usr/local/moneydance/.install4j/i4jruntime.jar:/usr/local/moneydance/moneydance.jar:/usr/local/moneydance/appsrc.jar:/usr/local/moneydance/jfreechart-1.0.13.jar:/usr/local/moneydance/jcommon-1.0.16.jar:/usr/local/moneydance/tablelayout.jar com.install4j.runtime.Launcher launch Moneydance true false /usr/local/moneydance/error.log /usr/local/moneydance/output.log false true false s_1s3rict.gif true true 529 101 20 20 Arial 0,0,0 8 500 version 2010 20 40 Arial 0,0,0 8 500 -1
Aieee, what an indigestible glob! No wonder it makes trouble. At any rate now I know that Moneydance is gumming up my audio, so I close it and voilá! I have sound again. If you don’t have alsautils installed then by all means hie yourself to your package manager and install it. Then you can run simple and useful sound tests, like this one for testing two stereo speakers:
$ speaker-test -t wav -c 2 -l 2
You will hear a pleasant woman’s voice saying “front left, front right” and hopefully coming out of the correct speakers. -l 2 means run the test twice, then stop.
This is a great example of why I prefer command-line tools. They stay the same so you don’t have to continually re-learn them, and have complete functionality. GUI programmers keep “improving” and changing and abandoning their interfaces, and they rarely support a complete set of command options.
*Not my friends.