If you want the sound on your computer to be more than the speaker on your PC going "bing" occasionally, you must have a separate sound card or one built into your computer's motherboard. Games are a reason to add a sound card, if the games rely on sound effects or other audio cues. Also, sound cards let you play music and communicate on the Internet using a variety of communications tools.
To give you an idea of the features that a sound card can provide, the following lists features that are included in the popular Sound Blaster 16 sound card:
Sound recording and playback — The card can convert analog sound into 8-bit or 16-bit digital numbers. To convert the sound, the board samples the sound in waves from 5 kHz to 48 kHz, or 5000 to 48,100 times per second. (Of course, the higher the sampling, the better the sound and larger the output.)
Full-duplex support — This allows for recording and playback to occur at the same time. This is particularly useful for bidirectional Internet communication or simultaneous recording and playback.
Input/output ports — Several different ports on the board enable you to connect other input/output devices. These ports include:
Line-In — Connects an external CD player, cassette deck, synthesizer, MiniDisc, or other device for recording or playback. If you have a television card, you might also patch that card's line out to your sound card's line in.
Microphone — Connects a microphone for audio recording or communications.
Line-Out (Speaker Out) — Connects non-powered speakers, headphones, or a stereo amplifier.
Joystick/MIDI — Connects a joystick for gaming or MIDI device.
Internal CD Audio — This internal port connects the sound card to your computer's internal CD-ROM board (this port isn't exposed when the board is installed).
Sound drivers provided in Linux come from many sources, including a project that no longer exists: Open Sound System/Free (OSS/Free). If your sound card isn't supported in Red Hat Linux, try the OSS/Linux package to see if that package supports your sound card (go to www.opensound.com/oss.html). If it works, you can purchase the sound package.
Caution? |
Before you install a separate sound driver distribution, check to see if your current Red Hat distribution already has the most recent sound driver. When possible, use the driver that's distributed with the kernel. If you have tried the procedures in this book and you still don't have a working sound card, read the following file: /usr/src/linux*/Documentation/sound/README.OSS. Also, you can visit www.linux.org.uk/OSS for a list of supported cards. Or, you could try the Advanced Linux Sound Architecture at www.alsa-project.org, which is another project offering open-source sound drivers. |
The devices that the audio programs use to access audio hardware in Red Hat Linux include:
/dev/audio, /dev/audio1 — Devices that are compatible with Sun workstation audio implementations (audio files with the .au extension).
/dev/cdrom — Device representing your first CD-ROM drive. (Additional CD-ROM drives are located at /dev/cdrom1, /dev/cdrom2, etc.)
/dev/dsp, /dev/dsp1 — Digital sampling devices, to which many audio applications direct sound.
/dev/mixer, /dev/mixer1 — Sound-mixing devices.
/dev/sequencer — Device that provides low-level interface to MIDI, FM, and GUS.
/dev/midi00 — Device that provides raw access to midi ports.
/dev/sndstat — Device that displays the status of sound drivers.
Tip? |
Nodes in the /dev directory, such as /dev/audio, aren't just regular files. They represent access points to the physical devices (hard disks, COM ports, etc.) that are connected to your system, or to pseudo-devices (such as Terminal windows). For example, to find out the device of your current Terminal window, type tty. Then send some data to that device. For example, if your device name is /dev/pts/0, type: $ echo "Hello There" > /dev/pts/0 |
The words "Hello There" appear in that Terminal window. You can try sending messages among several Terminal windows. If a user who is logged on to the computer has terminal permissions open, you can send messages to him or her in this way, too. (I knew people who would send a dictionary file to an unsuspecting user's terminal. Although it wasn't destructive, it was annoying if you were trying to get work done.)
For general information about sound in Linux, see the Sound-HOWTO (for tips about sound cards and general sound issues) and the Sound-Playing-HOWTO (for tips on software for playing different types of audio files).
Note? |
You can find Linux HOWTOs at www.tldp.org. |
During the first start-up after you install Red Hat Linux, the Red Hat Setup Agent tries to detect and configure your sound card. If that process was successful, you can skip this procedure. If your sound card wasn't detected or if you add a card later, here are a few things you can try:
Insert a music CD into the drive and see if it plays.
Tip? |
Audio volume is set fairly low by default. If you can barely hear your audio, click Sound & Video ? Volume Control (from the Red Hat menu) to increase the volume level. Move the sliders to adjust the volume to your taste. Alternatively, from the command line type aumix -v 100 in a Terminal window to turn the volume all the way up, so you can adjust sound from your volume knobs. |
From the Red Hat menu, click System Settings ? Soundcard Detection (this runs the redhat-config-soundcard command). If your sound card was detected, an Audio Devices window should appear, as shown in Figure 8-1. Click the Play Test Sound button and you should hear a test sound. Click OK to finish up.
Figure 8-1: The Audio Devices (redhat-config-soundcard) window detects your sound card.
If the sound card still isn't detected, try the Sound Configuration Utility (you may need to install the sndconfig package from CD #3), as follows:
Run the following command as root user from a Terminal window:
# /usr/sbin/sndconfig
A sndconfig window is displayed, asking ask if you want to probe for Plug-and-Play cards. Press Enter to select OK.
If the utility finds a sound card that it recognizes, it displays the name of that card and asks if you want to configure it. If the sound card was detected, press Enter to select OK.
A message warns you that you are replacing the old /etc/conf.modules file. Press Enter to select OK.
A message tells you that a sound sample will play to check if the card is configured properly. Press Enter to select OK.
You are asked if you heard the sound.
If you hear the sound, select Yes and skip to Step 12. Otherwise select No to continue.
You are asked to manually configure your sound card. Press Enter to select OK.
A list of sound cards is displayed. Select your card and press Enter to select OK.
Select OK to try the sound card again.
You are asked again if you were able to hear the sample. If you hear the sound, select Yes to continue. Otherwise select No to try a different card.
You are warned that a new /etc/modules.conf file is being created (and the old one is being backed up). Press Enter to select OK.
At this point, you can try playing some audio. Insert a CD and open one of the CD players described in the following section.
Tip? |
If there is a data CD in your CD drive, you may not be able to simply eject it to play your music CD. To eject a data CD, close any windows that may have an open file from the CD, then unmount the CD in your drive (if one is mounted) by typing umount /mnt/cdrom as root user from a Terminal window. Then you can eject the old CD and place an audio CD in the drive. |
The player that pops up automatically when you insert a CD (on the GNOME desktop) is the gnome-cd player. However, several CD players that come with Red Hat Linux can be used to play CDs. Here are your choices for playing CDs with Red Hat Linux:
CD Player (gnome-cd) — This is the default CD player for the GNOME desktop. Besides having standard play buttons, this player lets you get track information automatically from a CD database (such as freedb.org). Or, if your CD isn't listed in the database, you can enter your own track information manually.
KsCD Player (kscd) — The KsCD player comes with the KDE desktop. To use KsCD, the kdemultimedia package must be installed. From the Red Hat menu (KDE desktop), click Sound & Video ? KsCD (or type kscd from a Terminal window). Like gnome-cd, this player lets you get title, track, and artist information from the CD database. KsCD, however, also lets you submit information you type in yourself to a CD database (if your CD isn't found there).
Grip (grip) — While the Grip window is primarily used as a CD ripper, it can also play CDs. Click Sound & Video ? More Sound & Video Applications ? Grip. It includes tools for gathering data from and submitting data to CD databases. It also includes tools for copying (ripping) CD tracks and converting them to different formats (encoding). (The grip package must be installed to use this command.)
CDPlay (cdp) — If you don't have access to the desktop, you can use the text-based cdp command. This player lets you use keyboard keys to play your CD, select tracks, go forward or back, or eject. (The cdp package must be installed to use this command.)
X Multimedia System (xmms) — The xmms player plays a variety of audio formats, but can also play directly from a CD.
If you prefer to use one of these players, you can disable automatic startup of gnome-cd by disabling automatic play in your CD Properties window (as described in the next section). The gnome-cd and cdp CD players are then described.
Note? |
If you try some of these CD players and your CD-ROM drive is not working, see the sidebar "Troubleshooting Your CD-ROM" for further information. |
When you put an audio CD into your CD-ROM drive, a CD player automatically pops up on your desktop. If you are using the GNOME desktop, you can thank magicdev. The magicdev process monitors your CD-ROM drives and opens a CD player when it sees an audio CD.
The fact that inserting a CD starts a player automatically is nice to some people and annoying to others. If you just want the CD to play, this behavior is a good thing. However, if you want to choose your own CD player or not play the CD until you choose, you may find auto-playing a bother. If you insert a data CD or a blank CD, magicdev exhibits different behavior. Here is what magicdev does by default:
Audio CD — When the music CD is inserted, magicdev starts the gnome-cd CD player and starts to play the first track of the CD.
Data CD — When a data CD is inserted, the CD is mounted on your file system, any auto-run program that may be on the CD is launched, and a file manager window opens. The first CD drive's mount point (/dev/cdrom) is /mnt/cdrom. If you have two drives, the second (/dev/cdrom1) is mounted on /mnt/cdrom1 (and so on).
Blank CD — When a blank CD is inserted, a nautilus window opens with burn:/// as the location.
You can change the behavior of magicdev on the CD & DVD preferences window. As you might guess from its name, you can change behavior for both CDs and DVDs as follows:
From the Red Hat menu, click Preferences ? CD Properties. The CD & DVD preferences window appears.
For Data CDs, select from the following options:
Mount CD when inserted — If this is selected, when a data CD is inserted it is automatically mounted in a subdirectory of /mnt. This option is on by default.
Start auto-run program on newly mounted CD — If this is selected, after a data CD is mounted, the user is asked to choose whether to run an auto-run program from the CD. This option is on by default if the first option is checked.
Open file manager window for newly mounted CD — If this is selected, after a data CD is mounted, a file manager window opens to display the contents of the top-level directory of the CD. For the first CD drive, the directory is /mnt/cdrom. This option is on by default if the first option is checked.
For Audio CDs, you can select "Run command when CD is inserted" to have the CD start playing automatically after it's inserted. The command shown in the box labeled Command is used to play the CD. By default, the option is on, and the gnome-cd player is chosen for you.
For blank CDs, the nautilus window opens with burn:/// as the location. With this feature enabled, you can drag-and-drop files on the nautilus window to gather the files you want to write to CD. Click Write to CD to burn the selected files to the CD.
For DVDs, click the box next to "Run command when DVD (video) is inserted" to have the DVD play automatically (using the vlc command) when you insert a DVD.
Click Close.
Like most graphical CD players, the gnome-cd player has controls that look similar to what you would see on a physical CD player. If you are using the GNOME desktop, from the System Menu select Sound & Video ? CD Player, or from a Terminal window, type:
$ gnome-cd &
The interface for adding information about the CD and its tracks is very nice. Click the Open Track Editor button. If you have an active connection to the Internet, gnome-cd automatically tries to grab track information for your CD, so you may already see the CD title and track name for each song when you open the editor.
If information about the CD doesn't appear, you can add Artist and Title information about the CD yourself. Then you can select each track to type in the track name. To add the name of the artist and the disc title, click in the appropriate box and type in that information. Figure 8-2 shows the CD Player and the CDDB Track Editor.
If you are working from a dumb terminal or just don't have your X desktop running, you can run the cdp utility (which comes with Red Hat Linux) to play CDs. I don't suggest running this from a Terminal window; it doesn't display properly. First, insert the music CD you want to play. Then, to start cdp, at a shell prompt type:
$ cdp
You should see a blue screen containing the cdp display. If instead of starting on the first track you want to start on another track (for example, track 5), type:
$ cdp play 5
When cdp starts, you can see all the tracks, how long each track plays, and total play time. To control the play of the CD, use the following controls (turn on Num Lock to use these numbers from the numeric keypad):
9 — Play
8 — Pause/Resume
7 — Stop
6 — Next Track
5 — Replay Current Track
4 — Previous Track
3 — Forward 15 Seconds
2 — Quit (Stop Music, Exit, and Eject)
1 — Back 15 Seconds
0 — Exit (Continue Music and Exit)
. — Help (Press the period key)
The cdp display also lets you enter the names of the artist, CD, and each song. Because this information is saved, you can see it each time you play the CD. Type these commands while the cdp display is showing to edit information about the CD currently playing:
a — Edit the Artist Name and press Enter.
c — Edit the CD Name and press Enter.
Enter — Edit the title of the current song and press Enter again.
Caution? |
If you try to edit a song name and cdp crashes, type eject to stop the CD from playing. Editing the song name seems to work better if you pause the song first. |
The arrow keys are also pretty handy for controlling CDs in cdp. The up arrow is for pause/play, and the left arrow is to go back a track. The right arrow is to go forward a track, and the down arrow is to eject.
The XMMS (X Multimedia System) Audio Player provides a graphical interface for playing music files in MP3, Ogg Vorbis and WAV, and other audio formats. XMMS has some nice extras too, which include an equalizer, a playlist editor, and the ability to add more audio plugins. If the player looks familiar to you, that's because it is styled after the Windows winamp program.
Note? |
Red Hat removed all software that does MP3 encoding or decoding due to patent concerns related to MP3 format. Although the XMMS player was designed to play MP3 files, the XMMS plug-in required to actually decode MP3 is not included with Red Hat Linux. To add MP3 support back into Red Hat Linux, you can get and install an MP3 plugin. RPM packages are available from several different sources, including www.xmms.org and www.gurulabs.com/downloads.html. |
You can start the XMMS Audio Player by selecting Sound & Video ? Audio Player or by typing the xmms command from a Terminal window. Figure 8-3 consists of the XMMS Audio Player with the associated equalizer (below) and the Playlist Editor (to the right).
As noted earlier, you can play several audio file formats. Supported audio file formats include the following:
MP3 (with added plugin)
Ogg Vorbis
WAV
AU
CD Audio
CIN Movies
You can get many more audio plugins from xmms.org. The XMMS Audio Player can be used in the following way:
Obtain music files by either:
Ripping songs from a CD or copying them from the Web so that they are in an accessible directory.
Inserting a music CD in your CD-ROM drive. (Xmms expects the CD to be accessible from /dev/cdrom.)
From the Red Hat menu, click Sound & Video ? Audio Player. The X Multimedia System player appears.
Click the Eject button. The Load files window appears.
If you have inserted a CD, the contents of /mnt/cdrom appear in the Files pane. Select the files you want to add to your Playlist and click the Add Selected Files or click the "Add all Files in Directory" button to add all songs from the current directory. To add audio files from your file system, browse your files and directories and click the same buttons to add the audio files you want. Select Close.
Click the Play List button (the tiny button marked PL) on the console. A Playlist Editor window appears.
Double-click the music file, and it starts to play.
With a file selected and playing, here are a few actions you can take:
Control play — Buttons for controlling play are what you may expect to see on a physical CD player. From left to right, the buttons let you go to a previous track, play, pause, stop, go to the next track, or eject. The eject button opens a window, allowing you to load the next file.
Adjust sound — Use the left slider bar to adjust the volume. Use the right slider bar to change the right-to-left balance.
Display time — Click in the elapsed time area to toggle between elapsed time and time remaining.
View file information — Click the button in the upper-left corner of the screen to see the XMMS menu. Then select View File Info. You can often find out a lot of information about the file: title, artist, album, comments, and genre. For an Ogg file, you can see specific information about the file itself, such as the format, bit rate, sample rate, frames, file size, and more. You can change or add to the tag information and click Save to keep it.
When you are done playing music, click the Stop button to stop the current song. Then click the X in the upper-right corner of the display to close the window.
Special features of the XMMS Audio Player let you adjust high and low frequencies using a graphic equalizer and gather and play songs using a Playlist Editor. Click the button marked EQ next to the balance bar on the player to open the Equalizer. Click the button marked PL next to that to open the Playlist Editor.
The Equalizer lets you use slider bars to set different levels to different frequencies played. Bars on the left adjust lower frequencies, and those on the right adjust higher frequencies. Click the EQ button to open the Equalizer. Here are tasks you can perform with the Equalizer:
If you like the settings you have for a particular song, you can save them as a Preset. Set each frequency as you like it and click the Preset button. Then choose Save ? Preset. Type a name for the preset and click OK.
To reload a preset you created earlier, click the Preset button and select Load ? Preset. Select the preset you want and click OK. The settings change to those of the preset you just loaded.
The small window in the center/top of the Equalizer shows the sound wave formed by your settings. You can adjust the Preamp bar on the left to boost different levels in the set range.
The Playlist Editor lets you put together a list of audio files that you want to play. You can add and delete files from this list, save them to a file, and use them again later. Click the PL button in the XMMS window to open the Playlist Editor.
The Playlist Editor allows you to:
Add files to the playlist — Click the Add button. The Load Files window appears. Select the directory containing your audio files (it's useful to keep them all in one place) from the left column. Then either select a file from the right column and click Add selected files or click Add all files in the directory. Click OK. The selected file or files appear in the playlist.
Select files to play — To select from the files in the playlist, use the previous track and next track buttons in the main XMMS window. The selected file is highlighted. Click the Play button to play that file. Alternatively, you can double-click on any file in the playlist to start it playing.
Delete files from the playlist — To remove files from the playlist, select the file(s) you want to remove (next/previous track buttons), right-click the playlist window, and click Remove ? Selected . The selected files are removed.
Sort files on the playlist — To sort the playlist in different ways, click and hold the Misc button and move the mouse to select Sort List. Then you can select Sort List to sort by Title, Filename, Path and Filename, or Date. You can also randomize or reverse the list.
Save the playlist — To save the current playlist, hold the mouse button down on the List button and then select Save. Browse to the directory you want, and then type the name you want to assign to the playlist and click OK.
Load the playlist — To reload a saved playlist, click the List button. Select a previously saved playlist from the directory in which you saved it and click OK.
There is also a tiny set of buttons on the bottom of the Playlist Editor screen. These are the same buttons as those on the main screen used for selecting different tracks or playing, pausing, stopping, or ejecting the current track.
MIDI stands for Musical Instrument Digital Interface. MIDI files are created from synthesizers and other electronic music devices. MIDI files tend to be smaller than other kinds of audio files because, instead of storing the complete sounds, they contain the notes played. The MIDI player reproduces the notes to sound like a huge variety of MIDI instruments.
There are lots of sites on the Internet for downloading MIDI files. Try the Ifni MIDI Music site (www.ifni.com), which contains songs by the Beatles, Led Zeppelin, Nirvana, and others organized by album. Most of the MIDI music is pretty simple, but you can have some fun playing with it.
Red Hat Linux comes with a couple of MIDI players, including kmid and kmidi. Neither player is installed by default (they are both in the kmultimedia package on CD #3). Both provide a GUI interface for midi music. The more interesting of the two midi players is KMidi. There is also the timidity MIDI player, which lets you run MIDI audio from a Terminal window.
Note? |
Use the timidity or kmidi MIDI player if your sound card doesn't include MIDI support. Both can convert MIDI input into WAV files that can play on any sound card. To start timidity, type timidity file.mid & at the command-line prompt. |
To start kmidi, click Sound & Video ? More Sound & Video Applications ? KMidi (or type kmidi & from a Terminal window). Figure 8-4 shows the KMidi window.
The instrument name is shown for each track (on the left), while bars (above) show the sound level for each track as it plays.
There are many different formats for storing and compressing speech and music files. Because music files can be large, they are typically stored in a compressed format. While MP3 has been the compression format of choice, Ogg Vorbis is quickly becoming a favorite format for compressing music in the open-source community.
Tools that come with Red Hat Linux for converting and compressing audio files include:
sox — A general-purpose tool for converting audio files among a variety of formats.
oggenc — A tool for specifically converting music files to Ogg Vorbis format.
If you have a sound file in one format, but you want it to be in another format, Linux offers some conversion tools you can use to convert the file. The Sox utility can translate to and from any of the audio formats listed in Table 8-1.
File Extension or Pseudonym |
Description |
File Extension or Pseudonym |
Description |
---|---|---|---|
.8svx |
8SVX Amiga musical instrument description format. |
.aiff |
Apple IIc/IIgs and SGI AIFF files. May require a separate archiver to work with these files. |
.au |
Sun Microsystems AU audio files. This is a popular format. |
.avr |
Audio Visual Research format, used on the Mac. |
.cdr |
CD-R files used to master compact disks. |
.cvs |
Continuously variable slope delta modulation, which is used for voice mail and other speech compression. |
.dat |
Text data files, which contain a text representation of sound data. |
.gsm |
Lossy Speech Compression (GSM 06.10), used to shrink audio data in voice mail and similar applications. |
.hcom |
Macintosh HCOM files. |
.maud |
Amiga format used to produce sound that is 8-bit linear, 16-bit linear, A-law, and u-law in mono or stereo. |
.ogg |
Ogg Vorbis compressed audio, which is best used for compressing music and streaming audio. |
.ossdsp |
Pseudo file, used to open the OSS /dev/dsp file and configure it to use the data type passed to Sox. Used to either play or record. |
.sf |
IRCAM sound files, used by CSound package and MixView sample editor. |
.smp |
SampleVision files from Turtle Beach, used to communicate with different MIDI samplers. |
.sunau |
Pseudo file, used to open a /dev/audio file and set it to use the data type being passed to Sox. |
.txw |
Yamaha TX-16W from a Yamaha sampling keyboard. |
.vms |
Used to compress speech audio for voice mail and similar applications. |
.voc |
Sound Blaster VOC file. |
.wav |
Microsoft WAV RIFF files. This is the native MS Windows sound format. |
.wve |
8-bit, a-law, 8 kHz sound files used with Psion Palmtop computers. |
.raw |
Raw files (contain no header information, so sample rate, size, and style must be given). |
.ub, .sb, .uw, .sw, .ul, .al, .lu, .la, .sl |
Raw files with set characteristics. ub is unsigned byte; sb is signed byte; uw is unsigned word; sw is signed word; and ul is ulaw. |
Tip? |
Type sox -h to see the supported audio types. This also shows supported options and effects. |
If you are not sure about the format of an audio file, you can add the .auto extension to the filename. This triggers Sox to guess what kind of audio format is contained in the file. The .auto extension can only be used for the input file. If Sox can figure out the content of the input file, it translates the contents to the sound type for the output file you request.
In its most basic form, you can convert one file format (such as a .wav file) to another format (such as an .au file) as follows:
$ sox file1.wav file1.au
To see what Sox is doing, use the -V option. For example:
$ sox -V file1.wav file1.voc sox: Reading Wave file: Microsoft PCM format, 2 channel, 44100 samp/sec sox: 176400 byte/sec, 4 block align, 16 bits/samp, 50266944 data bytes sox: Input file: using sample rate 11025 size bytes, style unsigned, 1 channel sox: Input file1.wav: comment "file1.wav" sox: Output file1.voc: using sample rate 44100 size shorts, encoding signed (2's complement), 2 channels sox: Output file: comment "file1.wav"
You can apply sound effects during the Sox conversion process. The following example shows how to change the sample rate (using the -r option) from 10,000 kHz to 5000 kHz:
$ sox -r 10000 file1.wav -r 5000 file1.voc
To reduce the noise, you can send the file through a low-pass filter. Here's an example:
$ sox file1.voc file2.voc lowp 2200
For more information on Sox and to get the latest download, go to the SoX — Sound eXchange — home page (sourceforge.net/projects/sox/).
The oggenc command takes music or other audio data and converts it from uncompressed formats (such as WAV, raw, or AIFF) to the compressed OGG Vorbis format. Using OGG Vorbis, audio files can be significantly reduced without a noticeable loss of sound quality. (Using default settings in oggenc, I reduced a 48MB WAV music file to 4MB.)
In its most basic form, you can use oggenc with one or more WAV or AIFF files following it. For example:
$ oggenc *.wav
This command would result in all files ending with .wav in the current directory to be converted to OGG Vorbis format. An OGG file is produced for each WAV file, with oggenc substituting .ogg for .wav as the file suffix for the compressed file. OGG Vorbis files can be played in many different CD players in Linux, including the xmms window (described earlier).
Tip? |
If you want to rip music files from a CD and compress them, you can use the grip window (described later in this chapter). Grip allows you to select oggenc as the tool to do the file compression. |
Cross-Reference? |
If you are interested in making a CD jukebox that rips, records, and compresses music CDs using oggenc and other open source software, check out the book Linux Toys by Christopher Negus and Chuck Wolber from Wiley Publishing. |