ONLamp.com    
 Published on ONLamp.com (http://www.onlamp.com/)
 See this if you're having trouble printing code examples


FreeBSD Basics Using Sound on FreeBSD

by Dru Lavigne
09/19/2002

In today's article, I'd like to continue configuring a multimedia workstation by concentrating on sound. First, I'll quickly demonstrate how to get sound working, then I'll move on to some of the sound-related ports in the ports collection.

If you haven't read the multimedia section of the FreeBSD handbook lately, you'll be pleasantly surprised. It has been totally revamped and is definitely the first place to go to see if your sound card is supported, and if so, how to get it working under FreeBSD.

My system has a SoundBlaster PCI 128, so I simply need to add the pcm device to my kernel configuration file in order to enable that soundcard. Since I also plan on using a DVD player, I'll include the option to optimize the CPU for multimedia applications. Multimedia applications also use something known as LDT, which may or may not already be in your kernel configuration file; if it isn't, add it. These are the three lines I added to my kernel configuration file:

options		CPU_ENABLE_SSE		#used by DVD
options		USER_LDT		#used by many apps
device 		pcm			#used by SoundBlaster

I then rebuilt my kernel using the instructions found at http://www.freebsd.org/handbook/kernelconfig-building.html.

There are several sysctl values that can be tweaked to improve multimedia performance. Two of them are read-only, meaning that you must place these values in the file /boot/loader.conf, like so:

hw.ata.atapi_dma="1"		
hw.ata.ata_dma="1"

The other four values are placed in the file /etc/sysctl.conf. Note that, unlike the previous file, you don't use quotations around the values in this file:

kern.ipc.shmmax=67108864	
kern.ipc.shmall=32768
hw.snd.pcm0.vchans=4				
hw.snd.maxautovchans=4

If your soundcard doesn't use the pcm device, don't include that third sysctl value dealing with pcm0. If you use pcm1 instead of pcm0, change the 0 to a 1 when you add that sysctl value. Also note that you will need to reboot in order for all of your changes to take effect.

The first time I rebooted into my new kernel, I noticed something odd when I tried to mount a data CD-ROM: I kept getting this error message:

cd9660: /dev/acd0c: Device not configured

Normally, this error message indicates that there isn't a data CD in the CD-ROM bay. Since this wasn't the case, a search through the mailing lists revealed that this also occurs if you use cvsup to upgrade from FreeBSD 4.5 to 4.6, which I had. To update the necessary device drivers, I became the superuser and:

cd /dev
cp /usr/src/etc/MAKEDEV .
rm acd*
./MAKEDEV acd0

While I'm in this directory, I'll also change the permissions to the CD-ROM device file, so I'll be able to play audio CD-ROMs as a regular user, instead of having to become the superuser:

chmod 666 /dev/acd0c

Now I can start building some sound applications. I've tried most of the applications in the audio section of the ports collection, and I can honestly say that you'll be hard pressed to find a sweeter sound-playing utility than xmms. It is skinnable, even though it looks great by default; it has dozens of audio, visualization, and other plugins; it plays MP3s, MPEGs, WAVs, and Shoutcast, as well as CDs, and supports the use of CDDB servers. Thorough documentation of how to use its features can be found at www.xmms.org, along with screenshots, plugins, and skins.

To install this utility:

cd /usr/ports/audio/xmms
make install clean

I also installed all of the available plugins from the ports collection. Since there are several dozen, I'll list where they are located in the ports collection, along with a brief description and where they can be configured in xmms:

-----

These plugins, once installed, can be configured in the Audio I/O Plugins tab of Preferences:

/usr/ports/audio/xmms-a52dec			#a52/a53 decoder			
/usr/ports/audio/xmms-bonk			#plays bonk files
/usr/ports/audio/xmms-crossfade			#allows crossfading
/usr/ports/audio/xmms-fc			#future composer input
/usr/ports/audio/xmms-mad			#uses libmad
/usr/ports/audio/xmms-musepack			#mpegplus
/usr/ports/audio/xmms-osssurround		#surround sound
/usr/ports/audio/xmms-shn			#shorten compressed audio
/usr/ports/audio/xmms-sid			#plays sid files
/usr/ports/graphics/smpeg-xmms			#mpeg video support
/usr/ports/audio/xmms-sndfile			#libsndfile files
/usr/ports/audio/xmms-tfmx			#plays tfmx tunes

These plugins, once installed, can be configured in the Effect/General Plugins tab of Preferences:

/usr/ports/x11-clocks/xmms-alarm		#alarm 
/usr/ports/audio/xmms-crystality		#remasters mp3 sound
/usr/ports/audio/xmms-ladspa			#provides ladspa
/usr/ports/audio/xmms-liveice			#icecast streaming audio
/usr/ports/audio/xmms-pipe			#named pipe control
/usr/ports/audio/xmms-quix3dn			#3-d sound effect
/usr/ports/audio/xmms-sndstretch		#change pitch or speed
/usr/ports/audio/xmms-volnorm			#volume normalizer

These plugins, once installed, can be configured in the Visualization Plugins tab of Preferences:

/usr/ports/graphics/xmms-blursk			#blur scope
/usr/ports/graphics/xmms-finespectrum		#fine grain spectrum
/usr/ports/graphics/xmms-gforce			#music visualization
/usr/ports/graphics/xmms-goom			#cool music visualization
/usr/ports/graphics/xmms-infinity		#full screen interactive	
/usr/ports/graphics/xmms-jess			#awesome music visualization
/usr/ports/graphics/xmms-paranormal		#spectrum analyzer

-----

As of the writing of this article, all of the xmms-related ports installed flawlessly, with the following exceptions:

Now, let's take a quick tour of xmms. Instead of repeating the basic usage that is already well-documented at the xmms Web site, I'll instead give some first-hand tips to get you started. I'll assume that your CD-ROM and sound card are installed properly and that you were successful in getting FreeBSD to recognize your particular sound card.

Let's start with a music CD-ROM. From your Window Manager, start xmms and press Ctrl-P to bring up the Preferences screen. You'll note the various plugins tabs that I referred to earlier, and you'll recognize the plugins that you chose to install from the ports collection.

Related Reading

Unix Power Tools
By Shelley Powers, Jerry Peek, Tim O'Reilly, Mike Loukides

In the Audio I/O Plugins tab, click on CD Audio Player, then the Configure button. Under the Device tab, ensure your device is set to /dev/acd0c and the directory to /cdrom. Then, click on the CD Info tab if you would like to configure a CDDB server. CDDB servers are great, as they contain information regarding audio CDs, such as the names of the CD and artist, and the names of the songs on the CD. However, they do require you to be attached to the Internet when you first load an audio CD so that you can download that information. If you'd like that feature, click on Use CDDB and type in the name of your favorite CDDB server in the CDDB server type-in section. I use freedb.freedb.org.

Save your changes, insert an audio CD into your CD_ROM drive, and wait for the light to stop flashing. Then, click on the eject icon in xmms. Instead of ejecting the CD, xmms will give you a pop-up window, where you can choose which files to load. Navigate to /cdrom and you should see all of the CD's tracks in the file section. (If you don't, you probably forgot to change the permissions on /dev/acd0c.) Click on "Add all files in directory." If you chose to use a CDDB server and this is the first time you've played this CD, be patient; it takes a minute or two to download the details. Once the files are added, click on Close and you should see the name of each track in your Playlist. If you don't see a Playlist, click on the PL button to open up the Playlist window. If the various xmms icons for playing, stopping, and moving through the tracks aren't intuitive to you, spend a bit of time at www.xmms.org/documentation.html to familiarize yourself with the available features.

The xmms utility can play more than CDs. I tend to have eclectic music tastes, which means the CDs I like are rarely in stock in my community. Fortunately, the Internet is a great resource for discovering new artists. How else would I have known that I enjoy Jewish reggae, Middle Eastern pop, East Indian blues, electronica remixes of the classics, and even the occasional gothic rock? My spare time is usually spent finding and listening to new MP3s, so I always have a list of CDs to order when I visit my favorite music shop.

I use Mozilla, and since I have already installed the plugger port (see previous article), I simply have to click on the "play" hyperlink when I find an interesting MP3 on the Internet. You can also tell Mozilla to use xmms to play MP3s by going to Mozilla's Edit menu -> Preferences -> Helper Applications -> New Type. Type in "mp3" in the first three fields and "/usr/X11R6/bin/xmms" in the "Application to use" field.

In my home directory, I've created a directory called mp3s to store the MP3s I'd like to listen to while my CDs are on order. To tell xmms to play these mp3s, I press Shift-L and double-click on the directory where the MP3s are stored.

If you've installed the xmms-liveice plugin, you can also listen to Shoutcast. Head over to www.shoutcast.com, find something interesting, and click on the Tune In! button. When your browser asks you what to do with this type of file, choose to "Open using an application" and use /usr/X11R6/bin/xmms. When you get tired of listening, use the stop icon on xmms. If you don't want to be asked every time, go into Mozilla's Preferences -> Helper Applications -> New Type. Give the type a description, a file extension of "pls", a MIME type of "audio/x-scpls" and the application to use, "/usr/X11R6/bin/xmms." Hmmm, I may never need to turn on a radio again.

You'll find more stations at www.icecast.org. Most of these stations use a different MIME type, so go back into Helper Applications. This time, use an extension of "mpu" and a MIME type of "audio/x-mpegurl." I've had less luck with this MIME type; some stations come in fine, some sound like chipmunks on speed. If you know the workaround for this, let me know and I'll include it in the next article.

If you like to be visually entertained while listening to music, press Ctrl-P to open up the Preferences and click on Visualization Plugins. Highlight one of the plugins you installed, then click on "Enable plugin". I liked xmms-jess the best, with xmms-goom a close second. If you get tired of being entertained, re-click the enable button to toggle off the plugin. I've found that my screen freezes if I try to enable more than two visualization plugins at once.

While we're on visualization, let's take a look at skins. The first time you ran xmms a skins directory called .xmms/Skins was created for you in your home directory. Head over to www.xmms.org/skins.html and if you see a skin you like, download it to your Skins directory. To apply the new skin, press Alt-S and highlight the new skin to get an instant preview.

I also found that www.spacefem.com/xmms.shtml had a very nice collection of skins. If you're into skins, you'll find that most of the skins on the Internet are advertised as Winamp skins. Don't let that deter you; save them to your Skins directory and like magic they'll work on xmms. For example, I did an Internet search for the popular "mooamp" skin and now my xmms has its own "ecowlizer." Don't let the extension of the skin scare you off; my Skins directory has tar.gz, zip, wsz and png files all coexisting nicely together. So, feel free to spend some time browsing through www.winamp-skins.com.

If you've installed smpeg-xmms, you can also watch movies with the "mpg" extension. Simply press l (the letter ell) to select the previously- saved movie file. This plugin can be configured to display the movie in a centered window, in doublesize mode, or in fullscreen mode. To get you started, the Library of Congress has an extensive movie collection at lcweb.loc.gov/rr/mopic/ndlmps.html.

One of my favorite features is the alarm that gets installed with the xmms-alarm plugin. Use Ctrl-P to open up Preferences and click on the Effect/General Plugins tab. Highlight Alarm and go into the Configure button to set the alarm time and days. Unless you like to be jolted out of bed, don't set the volume to 100%. If you don't set a Playlist in the Options tab, you'll wake up to whatever song happens to be selected on your Playlist. Just make sure xmms is started before going to bed, if you want it to wake you up in the morning.

This should get you started on using xmms. In the next article, I'll finish the multimedia series by taking a look at DVD players, RealPlayer, and some miscellaneous ports to enhance your multimedia desktop.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Return to the BSD DevCenter.


Copyright © 2009 O'Reilly Media, Inc.