# Configuring Sound on Linux/Printable version

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.

## Using pacmd

Firstly run pacmd.
Next run the command list-sinks.
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.
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.

# Pulse Audio/Troubleshooting

This document entails issues you might encounter with PulseAudio.

## Verbose error capturing

Wanto to figure out what PulseAudio is doing? Try the following.

## Errors and solutions
### Wrong Sample Freq
#### Symptom

If you have the sample frequence set wrong you might encounter an error like this when you startup PulseAudio

#### Solution

Explicitly set the rate for the PulseAudio module in /etc/pulse/default.pa.

### Sound Stops Working
#### Symptom

You 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

Check pacmd command if your sound is not mute:
Second sink is mute so we need to unmute it
Additionaly restarting pulseaudio may be needed
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

RTP 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.

### Client
## TCP

Only uncompressed audio is supported.

### Configuring the Server

This 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).

### Configuring the Client

Simply set the environmental variable PULSE_SERVER to the destination and PulseAudio will redirect the stream over tcp to the provided destination.

# HW Address

This document will teach you how to find an address and confirm it is working.

## Find the hardware address
### Using aplay

The 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.
Note, for this card the notation for the physical address would be hw:0,3. While the device name, is HDMI

### Using /proc

Here 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.
An example of the output for device HDMI might be:
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.
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.

## Writing the hardware address

Now 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

Firstly, 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:
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.
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.
If you hear sound, enjoy—your card works and is fully compatible with your operating system.

# ALSA/Testing
## Testing Alsa on each channel

Modern 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:

# ALSA/Troubleshooting
## Errors and Solutions
### Kernel lacks appropriate modules
#### Symptom

Indicated 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

Add the appropriate modules to your kernel. In Ubuntu you can upgrade to the newest kernel and modules by issuing the following command:

### Invalid card specified
#### Symptom

If you encounter the following error it simply means you are targeting a non-existent or erroneous device:

#### Solution

This can often be remedied by simply specifying the device explicitly.

### Bad sample
#### Symptom

This is a rather complex option . Essentially, hardware expects a certain datatype for the sound sample, and you're providing the wrong one.

#### Solution

Specify the sample format, or amend the rate in the ALSA conf file.

### No channel count
#### Symptom

If you do not provide to ALSA the amount of channels you wish to output to, you'll get the following error:

#### Solution

Specify the amount of channels you wish to output too. Two is considered safe for the purpose of troubleshooting.