Sound troubleshooting

From Linuxintro
Revision as of 19:01, 2 April 2015 by imported>ThorstenStaerk (→‎strace'ing sound)

So you want your Linux system to play sound, but it does not? Follow these steps to analyze and solve the problem:

The Methodology

If your cables and volume are okay

  • Test if your sound card driver and cables are okay; play a test sound:
speaker-test

If you hear a sound

If you hear a sound, your cables and drivers are okay.

If you do not hear a sound

If you do not hear a sound, see if you get an error message.

If you do not get an error message

If you do not get an error message, it can be a driver issue. To find out, delete all sound devices and re-create them:

tweedleburg:~ # rm /dev/dsp*
tweedleburg:~ # udevtrigger

Check again with dd if=/dev/urandom of=/dev/dsp. If you still do neither get an error message nor sound, it is most probably a driver issue. Get yourself a USB soundcard and proceed.

If you get an error message

If you get an error message like this:

tweedleburg:~ # dd if=/dev/urandom of=/dev/dsp
dd: opening `/dev/dsp': Device or resource busy

You should find out what process blocks your sound card. Do this with the command lsof (list open files):

tweedleburg:~ # lsof | grep dsp              
mplayer   18251       root    4w      CHR              14,35               14320 /dev/dsp2

You see, mplayer is blocking /dev/dsp2, you third soundcard. Now find out what soundcard you are using:

tweedleburg:~ # ll /dev/dsp*
lrwxrwxrwx 1 root root       9 Jun 21 10:38 /dev/dsp -> /dev/dsp2
crw-rw---- 1 root audio 14, 19 Jun 21 10:36 /dev/dsp1
crw-rw---- 1 root audio 14, 35 Jun 21 10:36 /dev/dsp2

/dev/dsp points to /dev/dsp2, so the soundcard you are using is blocked by mplayer. So, kill mplayer if you are sure that is what you want:

killall mplayer

Knoppix

When there is no sound under Knoppix try

/etc/init.d/alsa-utils start

strace'ing sound

I called

strace -s 99 speaker-test 

verified that I heard sound. I noticed a lot of data was send to the file handle 6:

gettimeofday({1428021206, 3725}, NULL)  = 0
write(1, " 0 - Front Left\n", 16 0 - Front Left
)       = 16
write(6, "W", 1)                        = 1
write(4, "x", 1)                        = 1
futex(0x979b028, FUTEX_UNLOCK_PI_PRIVATE, -1221210112) = 0
gettimeofday({1428021206, 69604}, NULL) = 0
write(6, "W", 1)                        = 1
clock_gettime(CLOCK_MONOTONIC, {175, 791783767}) = 0
write(6, "W", 1)                        = 1
clock_gettime(CLOCK_MONOTONIC, {175, 792229634}) = 0
write(6, "W", 1)                        = 1
clock_gettime(CLOCK_MONOTONIC, {175, 792636529}) = 0
write(6, "W", 1)                        = 1
gettimeofday({1428021206, 71347}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC, {175, 793286612}) = 0
write(6, "W", 1)                        = 1
clock_gettime(CLOCK_MONOTONIC, {175, 793657888}) = 0
write(6, "W", 1)                      

Then I stopped the process using the CTRL_Z key combination. Then I found speaker-test's PID was 3156. Then I went to the file handles of this process:

linux-fpbq:~ # cd /proc/3156/fd
linux-fpbq:/proc/3156/fd # ll
total 0
lrwx------ 1 root root 64 Apr  2 20:34 0 -> /dev/pts/1
lrwx------ 1 root root 64 Apr  2 20:34 1 -> /dev/pts/1
lrwx------ 1 root root 64 Apr  2 20:33 2 -> /dev/pts/1
lr-x------ 1 root root 64 Apr  2 20:34 3 -> pipe:[19531]
l-wx------ 1 root root 64 Apr  2 20:34 4 -> pipe:[19531]
lr-x------ 1 root root 64 Apr  2 20:34 5 -> pipe:[19532]
l-wx------ 1 root root 64 Apr  2 20:34 6 -> pipe:[19532]
lrwx------ 1 root root 64 Apr  2 20:34 7 -> socket:[19537]

Now speaker-test writes into that file handle. Which process reads from it?

linux-fpbq:/proc/3156/fd # lsof -n +c 15 | grep 19532
speaker-test    3156            root    5r     FIFO        0,8      0t0      19532 pipe
speaker-test    3156            root    6w     FIFO        0,8      0t0      19532 pipe
threaded-ml     3156 3157       root    5r     FIFO        0,8      0t0      19532 pipe
threaded-ml     3156 3157       root    6w     FIFO        0,8      0t0      19532 pipe

seems to be threaded-ml