2.6. Configuring Sound
Fedora Core contains drivers for many different types of sound cards. However, it may be necessary to configure the sound path or select from different sound devices before your sound output is usable.
2.6.1. How Do I Do That?
To access the Soundcard Detection tool, select SystemAdministrationSoundcard Detection (or AdministrationSoundcard Detection in KDE). The window shown in Figure 2-21 will appear.
Figure 2-21. Soundcard Detection window
This window offers a minimal set of options: basically, you can select the default device to be used, and you can play a test sound.
To test your sound card, make sure that your speakers are plugged in and turned on, then click the Play button. You should hear a guitar chord played on the right, then the left, and then the right+left channels. If you don't, try selecting different device tabs (on the left side of the window) and PCM Device settings (at the bottom of the window) until you find a combination that works. Your system may have multiple sound cards (e.g., both a motherboard and PCI sound card), or there may be sound devices on your sound card that are not connected to a sound path that goes to your speakers; they may instead go to a modem, headphone jack, or thin air.
If you still don't hear anything, then it's time to break out the Volume Control/Mixer. In GNOME, you can do this either by right-clicking on the volume-control panel applet (the icon that looks like a speaker, shown way back in Figure 2-2) and selecting Open Volume Control, or by selecting the menu option SystemPreferencesVolume Control; the window shown on the right in Figure 2-22 will appear. In KDE, select Sound and VideoKMix or, if there's a volume-control icon in your panel, right-click it and select Show Mixer Window. The KMix window is shown on the left in Figure 2-22.
Figure 2-22. KDE KMix (left) and GNOME Volume Control (right)
To change which sound device is being configured, click FileChange Device and select the device from the list (in KMix, select the device using the "Current mixer" control).
Modern sound chips have many different inputs, outputs, and processing sections, but not all sound card designs implement all of these features, and even if the features are implemented, some of the inputs and outputs may not be connected to anything, or they may be connected to an input or output labeled with a different name. KMix presents controls for almost every available input, output, sound path routing option, and switch; GNOME's Volume Control lets you configure which controls you wish to display. This reduces clutter on the screen, but it also means that required controls may not be visible until you enable them.
To change the configuration of the Volume Control, select its menu option EditPreferences. The small checkbox list shown in Figure 2-22 will appear. Until you know which control does what, I'd recommend enabling all of the controls.
With all of the sound card controls in front of you, you can now experiment to see which control is preventing the test sound from reaching your ears. After each adjustment, test the result by clicking on the Play button in the Soundcard Detection tool.
First, check to make sure that your Pulse Code Modulation (PCM), Master, Headphone, and Master Mono outputs are turned up and not muted (i.e., the Volume Control speaker icons are not crossed out or the KMix LEDs are illuminated). If that doesn't solve the problem, experiment with the switches (such as External Amplifier) and the PCM output path/3-D processing.
After you have set the options you want, they will be saved and restored by default the next time you log in, so for most users this is a one-time (per user) configuration step.
Once you have found the correct sound device, select the Settings tab in the Audio Configuration window (Figure 2-21) and set the Default Audio Card and Default PCM Device. Click OK to save your configuration and exit.
Once you have sound working, you can change the volume level by placing your mouse over the volume-control panel applet and rolling the mouse wheel: away from you increases the volume; toward you decreases the volume. If you don't have a mouse wheel, click on the volume panel applet to reveal a slider control. To mute the sound, right-click on the panel applet and select Mute.
To configure sound when using a text console, type:
The AlsaMixer display is shown in Figure 2-23. Use the left/right cursor keys to select a control, up/down to set levels, Tab to switch between the Playback/Capture (Output/Input) views, M to mute, and Escape to exit.
Figure 2-23. AlsaMixer display
2.6.2. How Does It Work?
Fedora uses the Advanced Linux Sound Architecture system (ALSA), which has replaced the Open Sound System (OSS) used in older Linux kernels. The ALSA interface is generally more advanced than the OSS interface; however, OSS is used on many Unix systems, so ALSA also provides an OSS-compatible sound interface for the convenience of cross-platform software developers.
ALSA uses devices in the /dev/snd directory such as /dev/snd/controlC0, which is used by the Volume Control and KMix tools to control the first sound card (C0). Devices for OSS compatibility are in the /dev directory and include /dev/dsp, /dev/audio, and /dev/mixer.
Most sound chips have several inputsin some cases, a few dozen inputswhich are routed through various sound paths to arrive at one or more outputs. Most of these inputs have a description assigned by the chip designer, but it's not necessary for the sound card designer to use a particular input for its designated purpose, and it's also not guaranteed that the system builder will connect a given signal source to the appropriate input on the sound card. Since the ALSA drivers generally use the designations provided by the chip documentation, you may find situations where the Video control manages the CD-ROM volume, or the Headset control affects the main speaker output.
It's not uncommon for different sound card models to use the same chipsets, with the support circuitry for some features left off of the budget models. In these cases, ALSA has no idea which features are wired up and which ones have been omitted, which explains why there are so many controls that don't do anything.
When the system is shut down, the script /etc/rc.d/init.d/halt saves the sound configuration (including mixer settings) to /etc/asound.state. The state is restored by the Udev subsystem using the program /etc/dev.d/sound/alsa.dev when the sound devices are detected during system boot.
2.6.3. What About...
126.96.36.199. ...allowing multiple users to use a sound device at the same time?
When a user logs in, Fedora assigns ownership of the sound devices to that user and sets the permissions so that only that user can open them. If you want to allow several users (including those remotely logged in) to use sound at the same time, you can change the permissions of the sound devices so that they're universally accessible:
$ chmod 0777 /dev/snd/* /dev/mixer* /dev/audio* /dev/dsp*
To make this the default configuration, add this line to the end of the system-wide login script, /etc/profile.
188.8.131.52. ...controlling the volume levels from the command line or a script?
$ amixer Simple mixer control 'Master',0 Capabilities: pvolume pswitch pswitch-joined Playback channels: Front Left - Front Right Limits: Playback 0 - 31 Mono: Front Left: Playback 17 [55%] [on] Front Right: Playback 17 [55%] [on] Simple mixer control 'Master Mono',0 Capabilities: pvolume pvolume-joined pswitch pswitch-joined Playback channels: Mono Limits: Playback 0 - 31 Mono: Playback 14 [45%] [on] Simple mixer control 'Headphone',0 Capabilities: pvolume pswitch pswitch-joined Playback channels: Front Left - Front Right Limits: Playback 0 - 31 Mono: Front Left: Playback 20 [65%] [on] Front Right: Playback 20 [65%] [on] ...(Lines snipped)...
$ amixer scontrols Simple mixer control 'Master',0 Simple mixer control 'Master Mono',0 Simple mixer control 'Headphone',0 Simple mixer control '3D Control - Center',0 Simple mixer control '3D Control - Depth',0 Simple mixer control '3D Control - Switch',0 Simple mixer control 'PCM',0 ...(Lines snipped)...
$ amixer get Master Simple mixer control 'Master',0 Capabilities: pvolume pswitch Playback channels: Front Left - Front Right Limits: Playback 0 - 31 Mono: Front Left: Playback 20 [65%] [on] Front Right: Playback 20 [65%] [on]
$ amixer set Master 31 Simple mixer control 'Master',0 Capabilities: pvolume pswitch Playback channels: Front Left - Front Right Limits: Playback 0 - 31 Mono: Front Left: Playback 31 [100%] [on] Front Right: Playback 31 [100%] [on]
184.108.40.206. ...playing or recording an audio file from the command line?
There are many different audio file formats, and Fedora includes many different media players so that you can listen to them (including Totem, Mplayer, and Xine). Fedora Core also includes the sox utility to convert between formats; the sox package also includes a handy script named play that can be run from the command line. It converts just about any file into an appropriate format for output and sends the sound to your speakers:
$ play /usr/share/sounds/KDE_Startup_2.ogg
You can also apply various sox effects to the output. To play a file backward at a reduced volume:
$ play /usr/share/sounds/KDE_Startup_2.ogg -v 0.2 reverse
$ rec /tmp/x.ogg Send break (control-c) to end recording Ctrl-C
2.6.4. Where Can I Learn More?