Configuring Sound on Linux/Printable version
This is the print version of Configuring Sound on Linux You won't see this message or any elements not part of the book's content when you print or preview this page. |
The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/Configuring_Sound_on_Linux
Pulse Audio/Pulse apps
A typical PulseAudio distribution comes with numerous different programs. Refer to the man pages for more information. All official PulseAudio applications are prefixed with pa.
- paplay
- Plays wavs and select other audio files. This is not an mp3 player.
- pacat
- Plays and records streams
- PulseAudio alternative to aplay
- pasuspender
- Permits another device to access the sound device directly. Typically this is used for applications that can not plug into pulseaudio.
- pactl
- Controls the running pulseaudio server/daemon.
- padsp
- Creates a dsp and other devices for a transparent abstraction of a non-existent device.
- pacmd
- PulseAudio shell into pactl
Pulse Audio/Testing
To test a PulseAudio installation use pacat which is equivalent to ALSA's aplay utility. Warning: the output from this command may be _very_ loud.
pacat < /dev/urandom
Using pacmd
editFirstly run pacmd.
~$ pacmd
Welcome to PulseAudio! Use "help" for usage information.
Next run the command list-sinks.
>>> list-sinks
1 sink(s) available.
* index: 0
name: <alsa_output.pci_8086_27d8_sound_card_0_alsa_playback_0>
driver: <modules/module-alsa-sink.c>
flags: HW_VOLUME_CTRL LATENCY HARDWARE
state: RUNNING
volume: <0: 63% 1: 63%>
mute: <0>
latency: <78911 usec>
monitor source: <1>
sample spec: <s16le 2ch 44100Hz>
channel map: <front-left,front-right>
used by: <1>
linked by: <1>
module: <1>
description: <ALSA PCM on front:0 (AD198x Analog) via DMA>
Now you know the name of your sink and your index. In this example the name is alsa_output.pci_8086_27d8_sound_card_0_alsa_playback_0, and the index is 0. Now you will want a list of samples, use list-samples to accomplish this.
>>> list-samples
3 cache entries available.
name: <pulse-hotplug>
index: <0>
sample spec: <n/a>
channel map: <n/a>
length: <0>
duration: <0.0s>
volume: <0: 100% 1: 100%>
lazy: yes
filename: /usr/share/sounds/startup3.wav
name: <esound.gnome-2/logout>
index: <1>
sample spec: <s16le 2ch 44100Hz>
channel map: <front-left,front-right>
length: <317500>
duration: <1.8s>
volume: <0: 100% 1: 100%>
lazy: no
filename: n/a
name: <esound.gnome-2/login>
index: <2>
sample spec: <s16le 2ch 44100Hz>
channel map: <front-left,front-right>
length: <1361924>
duration: <7.7s>
volume: <0: 100% 1: 100%>
lazy: no
filename: n/a
Now you can use the command play-sample followed by the name of the sample, and the index or the sink-name to test your PulseAudio configuration.
>>> play-sample pulse-hotplug 0
-or-
>>> play-sample pulse-hotplug alsa_output.pci_8086_27d8_sound_card_0_alsa_playback_0
This page or section is an undeveloped draft or outline. You can help to develop the work, or you can ask for assistance in the project room. |
Pulse Audio/Troubleshooting
This document entails issues you might encounter with PulseAudio.
Verbose error capturing
editWanto to figure out what PulseAudio is doing? Try the following.
$ pulseaudio -v --log-target=stderr
Errors and solutions
editWrong Sample Freq
editSymptom
editIf you have the sample frequence set wrong you might encounter an error like this when you startup PulseAudio
$ pulseaudio
W: alsa-util.c: Device HDMI doesn't support 44800 Hz, changed to 48000 Hz.
Solution
editExplicitly set the rate for the PulseAudio module in /etc/pulse/default.pa.
load-module module-alsa-sink device=HDMI rate=48000
Sound Stops Working
editSymptom
editYou suddenly have no sound afer you wake up your computer or when you plug headphones, but alsamixer show that sound is enabled and volume can be hight.
Solution
editCheck pacmd command if your sound is not mute:
$ pacmd
Welcome to PulseAudio! Use "help" for usage information.
>>> list-sinks
2 sink(s) available.
index: 0
name: <alsa_output.pci-0000_01_05.1.hdmi-stereo>
driver: <module-alsa-card.c>
flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: SUSPENDED
suspend cause: IDLE
priority: 9050
volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
base volume: 100%
0,00 dB
volume steps: 65537
muted: no
...
* index: 1
name: <alsa_output.pci-0000_00_14.2.analog-stereo>
driver: <module-alsa-card.c>
flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: RUNNING
suspend cause:
priority: 9959
volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
base volume: 63%
-12,00 dB
volume steps: 65537
muted: yes
Second sink is mute so we need to unmute it
>>> set-sink-mute 1 false
Additionaly restarting pulseaudio may be needed
$ sudo /etc/init.d/pulseaudio restart
NOTE: If you play video using flash in Browser (like YouTube) you can enable sound but when you exit from pacmd the sound stop and when you try to enter pacmd again to show that pulseaudio is not running in the session, in this case refreshing the page with the video solve the issue.
Pulse Audio/Remote server
RTP
editRTP streams use multicast IP adresses like 224.0.0.56 (default) and UDP datagrams for transport. Multicasts are generally not allowed in Internet (blocked by ISPs). RTP is designed for low latency.
Server
edit $ pactl load-module module-rtp-recv
Client
edit $ pactl load-module module-rtp-send
TCP
editOnly uncompressed audio is supported.
Configuring the Server
editThis process is rather simple. You will need to load module-native-protocol-tcp. You can optionally specify an auth-ip-acl to permit/blacklist anonymous connections from specific ips or IP ranges (to list more than one, separate by semicolon).
$ pactl load-module module-native-protocol-tcp auth-ip-acl=192.168.1.138
Configuring the Client
editSimply set the environmental variable PULSE_SERVER to the destination and PulseAudio will redirect the stream over tcp to the provided destination.
$ PULSE_SERVER=192.168.1.146 totem
HW Address
This document will teach you how to find an address and confirm it is working.
Find the hardware address
editUsing aplay
editThe stock ALSA utility aplay can tell you the hardware addresses of the devices it is ready to use. Simply supply to aplay the --list-devices argument.
$ aplay --list-devices
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA ATI HDMI], device 3: ATI HDMI [ATI HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
Note, for this card the notation for the physical address would be hw:0,3. While the device name, is HDMI
Using /proc
editHere we will use proc to query our kernel for information.
By viewing the virtual file /proc/asound/cards your kernel will show you the device names for the cards it is has ready for use. If your card isn't listed here then your kernel does not support it. The device names can be found in the brackets.
$ cat /proc/asound/cards
An example of the output for device HDMI might be:
0 [HDMI ]: HDA-Intel - HDA ATI HDMI
HDA ATI HDMI at 0xfbee8000 irq 19
The kernel should have created a virtual directory for each card in /proc/asound. The directories associated with the card will be prefixed by 'card' and suffixed by the number of the card, ex., card0, card1, etc.; i.e., '0' in our example.
Inside of these directories you will find a simple list of files.
$ tree /proc/asound/card0/
/proc/asound/card0/
|-- codec#0
|-- id
|-- oss_mixer
`-- pcm3p
|-- info
`-- sub0
|-- hw_params
|-- info
|-- prealloc
|-- prealloc_max
|-- status
`-- sw_params
2 directories, 10 files
The most important file is the pcm3p/info, by examining this file we can finish our search for the hardware coordinates of the sound devices.
$ cat /proc/asound/card0/pcm3p/info
card: 0
device: 3
subdevice: 0
stream: PLAYBACK
id: ATI HDMI
name: ATI HDMI
subname: subdevice #0
class: 0
subclass: 0
subdevices_count: 1
subdevices_avail: 1
Writing the hardware address
editNow you know the basics about your card! Specifically, you'll need the card number, and the device number. These two are often seen in ALSA hardware notation as hw:CARD,DEVICE, which is totally dependent on the order the kernel detects them.
Test the address
editFirstly, make sure your device in question is un-muted! You can test the functionality of you default card at any time by using the following command:
cat /dev/urandom | aplay
This will bombard your card with random and totally irrelevant data. Your card will present this data to you in the form of sound à la modem noise. To stop that noise ^D (hold Control and press D). Alternatively, you can use the dd command to flash-test.
dd if=/dev/urandom count=5 | aplay
Presumably, if you're reading this tutorial your sound isn't working. You might want to explicitly test a sound device, or you might be having problems with the default and want to try out another device. Whatever have you, the -D argument to aplay does just that.
cat /dev/urandom | aplay -D hw:0,3 ## Where 0,3 is your hardware's coordinates
If you hear sound, enjoy—your card works and is fully compatible with your operating system.
ALSA/Testing
Testing Alsa on each channel
editModern versions of ALSA should include the utility speaker-test that permits you to test each channel of output, this is necessary to confirm modern systems are properly configured.
You can invoke this command on the ALSA Device:
speaker-test -D HDMI
ALSA/Troubleshooting
Errors and Solutions
editKernel lacks appropriate modules
editSymptom
editIndicated by:
- The virtual directory /proc/asound is not present
- The command aplay -l returns no sound cards present
- The sound card shows up under some hardware detection mechanism, i.e., lspci
Sometimes the cause of this is selectively pulling out modules suggested by a dist-upgrade, such as the kernel, without the kernel modules.
Solution
editAdd the appropriate modules to your kernel. In Ubuntu you can upgrade to the newest kernel and modules by issuing the following command:
$ sudo apt-get install linux-generic
Invalid card specified
editSymptom
editIf you encounter the following error it simply means you are targeting a non-existent or erroneous device:
$ cat /dev/urandom | aplay
ALSA lib pcm_hw.c:1207:(_snd_pcm_hw_open) Invalid value for card
aplay: main:546: audio open error: No such file or directory
Solution
editThis can often be remedied by simply specifying the device explicitly.
cat /dev/urandom | aplay -D hw:0,3
Bad sample
editSymptom
editThis is a rather complex option . Essentially, hardware expects a certain datatype for the sound sample, and you're providing the wrong one.
aplay: set_params:901: Sample format non available
Solution
editSpecify the sample format, or amend the rate in the ALSA conf file.
cat /dev/urandom | aplay -f S16_LE ## Where S16_LE is your desired rate
No channel count
editSymptom
editIf you do not provide to ALSA the amount of channels you wish to output to, you'll get the following error:
aplay: set_params:901: Channels count non available
Solution
editSpecify the amount of channels you wish to output too. Two is considered safe for the purpose of troubleshooting.
cat /dev/urandom | aplay -c 2 ## Two channels is stereo sound