**This is an old revision of the document!**

Understanding Linux Audio

Traditional Linux (such as Slackware, and as opposed to something more progressive like Red Hat and Fedora) deals with audio in its own unique way. This can be confusing to new users, or to experienced users who have never thought about it. It confuses people because almost no where in the audio schema is there a one-to-one mapping; you must think of audio processing in the computer as a series of rivers or streams, flowing from one or two sources internally, branching off one other for adjustment, and then re-joining at the end to deliver sound in the physical world.

The background and history of how and why is unimportant to actually using it, so this is a pragmatic overview of how and why Linux audio does what it does, and what you need to understand about it in order to control it.

You should read this even if you boot into Slackware and find that your sound just works.

1. Identify Physical Devices

The first step in forming a meaningful bond with the audio system of your computer is to do a full system scan of its audio devices. This sounds like it is a complicated technical process, but actually it's entirely non-technical:

  1. Sit down in front of your computer.
  2. Unplug any peripherals (the display notwithstanding).
  3. Take an assessment of each physical audio port.

Laptops

On laptops, the first thing you will probably notice is a headphone port and a microphone line-in. These are analogue audio ports.

Sometimes, unfortunately, a laptop design combines the headphone OUT port and the microphone IN jack. This not only cheats you out of versatility but it gets very confusing on the software side, so take special note of it should you have such a combined port.

Most laptops have, in addition to the audio ports that you see right away, inbuilt input and output: that is, a microphone (usually intended for use with a web cam) and speakers.

And finally, many laptops have HDMI or other digital audio outputs. You may or may not intend to use these, but you will need to account for them in software, so take note.

Desktops

On desktops and workstations, there are usually ports on the front and rear panels. For instance, you might find a headphone port and a microphone line-in for easy access in the front panel, and then six or seven more analogue audio ports in the back, usually meant to provide some degree of surround sound (or at least a left, right, and center channel).

Additionally, your desktop may have an HDMI port or other digital audio output. You may or may not intend to use these, but you will need to account for them in software, so take note.

2. Identify Sound Cards

TL;DR
Check your sound cards with aplay -l. The first one listed is where your sound goes to by default.

Now that you know the tributaries, you must go further up the river, as it were, to find the sources of the sound that is distributed to all of the different physical ports. Your computer may have 5 or 6 physical ports for sound devices, but usually all of those ports are wired back a single sound card (which are not always a separate card from your motherboard, so opening the computer and looking at internal components is not always as obvious as you might think).

To find out just how many sound cards you have, open a terminal a use aplay (for outputs) and arecord (for inputs) to find out how ALSA (Advanced Linux Sound Architecture) views your hardware:

bash-4.2# aplay -l
List of PLAYBACK Hardware Devices

card 0: SB [HDA ATI SB], device 0: ALC887-VD Analog [ALC887-VD Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: SB [HDA ATI SB], device 1: ALC887-VD Digital [ALC887-VD Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

From this sample output, we learn that this computer has two physical cards, feeding four different groups of ports. In this example, we can deduce that the first card, card0, is the motherboard, analogue sound system that feeds the analogue headphone and speaker ports. We can further deduce that the second card, card1, refers to the graphics card, not only because it is clearly labelled as NVidia but also because it is labelled as being HDMI.

List Order is Significant

TL;DR
Change default sound card settings with a .asoundrc config file.

The list being provided here is not arbitrary or just the order in which your computer has detected the audio devices. The first listed card (card0) is marked as the default destination for audio. That seems fine, as long as your audio is working as expected, but it becomes problematic if your desired default happens to be different (for instance, if you want to use HDMI for all your audio).

If you need to change the order of sound card dominance, create the file .asoundrc file in your home directory and tell your audio system to use a different card as its default.

Here is an example of an .asoundrc file that promotes the second card to be the default device:

defaults.ctl.card 1
defaults.pcm.card 1
defaults.timer.card 1

pcm.!default {
type hw
card 1
device 0
}

ctl.!default {
type hw
card 1
device 0
}

pcm.dsp {
type plug
slave.pcm "dmix"

Log out of your desktop session and log back in (or reboot if you prefer) and now the default sound output has shifted.

3. Map Sound Devices to their Controls

At this point, you have identified the sound cards in your system, and you have set which card is the default card. Now it's time to look at the software sound controls provided to you on your Linux desktop so that you know which control to use to raise, lower, and mute sound.

If you are used to a system that provides you one over-all volume control for everything, then the Linux desktop sound controls are bound to confound you. On a laptop, you might find that even with a mere three output ports (speakers, headphones, and digital) spread across two cards, you still have upwards of six different playback controls. On a desktop, those numbers each go up exponentially.

The reason for this, again, is that there is no 1:1 map between sound ports and the software that uses them. For example, one headphone and one stereo speaker output affords the opportunity to control at least (1) the headphone volume, (2) the speaker volume, and (3) all output (both the headphone and speaker) together: three controls for two physical outputs (that's without considering users who want left and right channels on separate controls). Take that example and apply it to a surround sound setup, and you begin to see the complexity of what is offered to a user.

Since Slackermedia cannot know your requirements, it's up to you to determine your ideal control scheme, but the first step is to understand which volume slider controls which sound port. The most efficient way to investigate this is alsamixer

launch alsamixer

Select appropriate card… Your goal is to find the valid sound outputs. Select an output, play the test sound. Repeat until you cycle through them all. When you find a good one, leave its volume high. When you find one that does nothing, lower its volume. Once finished, you have a map of known useful sound outputs and apparently-useless sound outputs.

Set Sound Preferences

Now let KDE know about your preferences. Go to KDE System Settings > Multimedia > Audio and Video Settings There are many backend options, but MPlayer is probably the best. After you set it, test your sound again to make sure this backend works as expected.

Finally go to KMix and open it.

Filter out all of the sound outputs you don't need. More or less, they useful ones should match the names in alsamixer.

The PCM device is an umbrella over all the sound on the card. So if you want ONE volume control to control BOTH speaker and headphone, then it's PCM that you are looking for. Set PCM as the volume control in Settings > Select Master Channel. Confusingly, this is different from the channel called MASTER that many cards have. Really it's selecting the CONTROL channel.

If you want control over headphone and speaker volume separately, then leave in separate controls in KMix.

If you have more than just a few speakers, then leave lots of controls in Kmix. It's all up to you.