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.
Most modern PCs include a sound card, often integrated into the motherboard. In the rare case that one isn't included (or the slightly more common case where it isn't supported in Linux), you can add a supported sound card starting for only a few dollars.
To give you an idea of the features that a sound card can provide, the following list summarizes features that are included in a popular 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 5,000 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 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 drive (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). However, the Advanced Linux Sound Architecture (ALSA) is the sound system that is integrated into the 2.6 kernel that comes with Fedora Core 3. The older OSS drivers are useful if ALSA does not support your sound card.
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, visit the Advanced Linux Sound Architecture at www.alsa-project.org site, home of the ALSA sound architecture. Also, you can visit www.linux.org.uk/OSS for a list of supported cards.
The devices that the audio programs use to access audio hardware in Fedora 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, and so on.)
/dev/dsp, /dev/dsp1 — Digital sampling devices, which many audio applications identify to access your sound card.
/dev/mixer, /dev/mixer1 — Sound-mixing devices.
/dev/sequencer — Device that provides a 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.
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, and so on) 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).
You can find Linux HOWTOs at www.tldp.org.
During the first start-up after you install Fedora, the Firstboot 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.
Audio volume is set fairly low by default. If you can barely hear your audio, click Sound & Video ®Volume Control (from the Applications 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 Applications menu, click System Settings ® Soundcard Detection (this runs the system-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 (system-config-soundcard) window detects your sound card.
At this point, you can try playing an audio file. Insert a CD and open one of the CD players described in the following section.
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 /media/cdrecorder as root user from a Terminal window. Then you can eject the old CD and place an audio CD in the drive. If the CD appears as an icon on the desktop, you can right-click the CD icon and select Eject to eject the disc.
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 Fedora Core can be used to play CDs. Here are your choices for playing CDs with Fedora Core:
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.
Rhythmbox (rhythmbox) — Import and manage your CD collection with Rhythmbox music management and playback software for GNOME. Rhythmbox uses Gstreamer on the audio backend and compresses music using Ogg Vorbis audio format. Besides allowing you to create playlists of your music library, Rhythmbox also has features for playing Internet radio stations. Open Rhythmbox from the Applications menu by selecting Sound & Video ® Music Player.
KsCD Player (kscd) — The KsCD player comes with the KDE desktop. To use KsCD, the kdemultimedia package must be installed. From the Applications menu (KDE desktop), select 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, and 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. Select Sound & Video ® 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 a player other than gnome-cd, you can disable automatic startup of gnome- cd by disabling automatic play in your Drives and Media Preferences window or having a different application launched to handle CDs (as described in the next section).
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 (gnome-cd) automatically pops up on your desktop and begins playing the CD. If you are using the GNOME desktop, you can thank the GNOME Volume Manager. The GNOME Volume Manager monitors your CD-ROM drives (as well as your other removable media, such as DVDs and digital cameras) and opens a CD player when it sees an audio CD.
If you don’t want to have CDs automatically start playing or if you want to use a different CD player by default, you can change that behavior using the GNOME Volume Manager's Drives and Media Preferences window. Refer to the GNOME Volume Manager section of Chapter 3 for details on how to change CD playing and mounting preferences.
If you are unable to play CDs on your CD-ROM drive, here are a few things you can check to correct the problem:
Verify that your sound card is installed and working properly (see “Configuring your sound card” earlier in this chapter).
Verify that the CD-ROM drive was detected when you booted Linux. If your CDROM drive is an IDE drive, type dmesg | grep ^hd. You should see messages about your CD-ROM that look like this: "hdc: CD-ROM CDU701, ATAPI CDROM drive" or this: "hdc: ATAPI 14X CD-ROM drive, 128kB Cache".
If you see no indication of a CD-ROM drive, verify that the power supply andcables to the CD-ROM are connected. To make sure that the hardware isworking, you can also boot to DOS and try to access the CD.
Try inserting a software CD-ROM. If you are running the GNOME or KDE desktop, a desktop icon should appear indicating that the CD mounted by itself. If no such icon appears, go to a Terminal window and type mount /media/cdrecorder. Then change to the /media/cdrecorder directory and list the contents using the command cd /media/cdrecorder; ls. This tellsyou if the CD-ROM is accessible.
If you get the CD-ROM working, but it fails with the message “CDROM device: Permission denied” when you try to play music as a nonroot user, the problem may be that device related to that medium is not readable by anyone but root. Type mount |grep media to see what device name represents the drive. Then (as the root user), if, for example, the CD device were /dev/hdc, type chmod 644 /dev/hdc to enable all users to read your CD-ROM and to enable the root user to write to it. One warning: if others use your computer, they will be able to read any CD you place in this drive.
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 &
If your computer is connected to the Internet, then for most CDs, you’ll see the title and artist information. Even obscure artists are represented in the free online databases. If the information isn’t available, you can enter it yourself.
The interface for adding information about the CD and its tracks is very nice. Click the Open Track Editor button. You can add Artist and Title information about the CD. 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 text box and type in that information. Figure 8-2 shows the CD Player and the CDDB Track Editor.
Figure 8-2: Play CDs and store artist, title, and track information with gnome-cd.
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 Fedora) to play CDs. I don’t suggest running this utility 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:
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.
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.
Rhythmbox provides the GNOME music player that lets you do everything, at least according to the Rhythmbox documentation. You can play music files, import music from CDs, and play Internet radio stations, all from one interface.
The first time you run Rhythmbox, the program displays a set-up wizard. You can tell Rhythmbox where you store your music files with the wizard dialog shown in Figure 8-3.
Figure 8-3: Defining where you store your music.
After you’ve gone through the setup wizard, you’ll see the main music library interface (see Figure 8-4). Rhythmbox makes it easy to organize even large collections of music files.
Figure 8-4: Viewing a music library with Rhythmbox.
The Red Hat and Fedora versions of Linux do not include support for playing MP3 files, due to patent issues. You can download updates for Rhythmbox at rpm.livna.net. You want the package streamer-plugins-mp3.
In addition to playing music files, Rhythmbox can launch Sound Juicer to rip CDs (see the section on Ripping CDs with Grip for more on ripping CD audio). Rhythmbox can also play Internet radio stations. The easiest way to do this is to find a streaming radio station (you want to look for Shoutcast PLS files, usually with a .pls extension). Save the PLS file, and then double-click on the file in the Nautilus file browser. Nautilus comes configured to launch Rhythmbox for playing audio. Figure 8-5 shows Rhythmbox with three Internet radio stations.
Figure 8-5: Rhythmbox playing Internet radio.
The site www.di.fm lists a number of free Internet radio channels.
The XMMS (X Multimedia System) Audio Player provides a graphical interface for playing music files in MP3, Ogg Vorbis, 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.
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 toactually decode MP3 is not included with Fedora Core. To add MP3 support back into Fedora Core, you can get and install an MP3 plugin. One place to get RPM packages that support MP3 decoding is http://rpm.livna.org. They are also available from other 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-6 consists of the XMMS Audio Player with the associated equalizer (below) and the Playlist Editor (to the right).
Figure 8-6: Play Ogg Vorbis and other audio files from the XMMS playlist.
Although the default theme is one that matches the Fedora Blue Curve theme, you can change the look of the player by right-clicking on XMMS and selecting Options ® Skin Browser. The theme shown in Figure 8-6 is called BrushedMetal_Xmms.
As noted earlier, you can play several audio file formats. Supported audio file formats include the following:
MP3 (with added plugin)
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 Applications menu, select 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 /media/cdrecorderappear in the Files pane. Select the files you want to add to your Playlist and click the Add Selected Files or 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 CD. 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 to change the settings.
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. You can also drag music files from the nautilus file manager onto the playlist window to add the files to 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 or files 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.
Fedora comes with the kmid MIDI player. Kmid is not installed by default (find it in the kdemultimedia package on the DVD). Kmid provides a GUI interface for midi music, including the ability to display karaoke lyrics in real time. There is also the timidity MIDI player (from the timidity++ package on the DVD), which lets you run MIDI audio from a Terminal window.
Use the timidity or kmid 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 kmid, type kmid & from a Terminal window.
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. Ogg Vorbis has the added benefit over MP3 of not being encumbered by patents.
Tools that come with Fedora 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.
Type sox -h to see the supported audio types. This also shows supported options and effects.
File Extension or Pseudonym
File Extension or Pseudonym
8SVX Amiga musical instrument description format.
Apple IIc/IIgs and SGI AIFF files. May require a separate archiver to work with these files.
Sun Microsystems AU audio files. This is a popular format.
Audio Visual Research format, used on the Mac.
CD-R files used to master compact disks.
Continuously variable slope delta modulation, which is used for voice mail and other speech compression.
Text data files, which contain a text representation of sound data.
Lossy Speech Compression (GSM 06.10), used to shrink audio data in voice mail and similar applications.
Macintosh HCOM files.
Amiga format used to produce sound that is 8-bit linear, 16-bit linear, A-law, and u-law in mono or stereo.
Ogg Vorbis compressed audio, which is best used for compressing music and streaming audio.
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.
Psion record.app format, newer than the WVE format.
IRCAM sound files, used by CSound package and MixView sample editor.
Speech audio SPHERE (Speech Header Resources) format from NIST (National Institute of Standards and Technology).
SampleVision files from Turtle Beach, used to communicate with different MIDI samplers.
Pseudo file, used to open a /dev/audio file and set it to use the data type being passed to Sox.
Yamaha TX-16W from a Yamaha sampling keyboard.
Used to compress speech audio for voice mail and similar applications.
Sound Blaster VOC file.
Microsoft WAV RIFF files. This is the native Microsoft Windows sound format.
8-bit, a-law, 8 kHz sound files used with Psion Palmtop computers.
Raw files (contain no header information, so sample rate, size, and style must be given).
.ub, .sb, .uw,
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.
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 5,000 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 (http://sox.sourceforge.net).
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 in size without a noticeable loss of sound quality. (Using the 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 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 audio players in Linux, including the XMMS player (described earlier).
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.
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.