Originally Published: Wednesday, 21 February 2001 Author: Brian Richardson
Published to: enhance_articles_hardware/Hardware Articles Page: 1/1 - [Printable]

Fiddling With USB Audio And Linux

Many Linux users aren't aware that the 2.4 kernel adds support for a number of interesting devices, as reported by Brian Richardson. Brian describes what he did with Linux and a set of Microsoft USB speakers. You should find it intriguing.

   Page 1 of 1  

For years, only Microsoft Windows users could truly benefit from the wide assortment of USB devices on the market. The average Linux user probably thinks that USB devices are keyboards, mice, joysticks and webcams, perhaps nothing to get too excited about. What many people may not know is that the 2.4 kernel adds support for more interesting devices, like USB Audio. This article describes my experience with Linux and a set of Microsoft USB speakers.

USB Audio?

Most users are not familiar with the concept of USB Audio, and many experienced computer users will squirm at the thought of using USB in place of their "standard" ISA or PCI sound card. What would compel a user to replace tried and true sound hardware with these strange speakers?

USB Audio devices adhere to the USB audio class specification. The USB device performs all of the digital-to-analog (D/A) conversion usually associated with a "standard" sound card. USB Audio devices receive simple packets that contain the binary information required to recreate 16-bit stereo sound.

Most USB Audio devices look like speakers with a USB plug in place of an audio jack. One speaker will have the speaker's controls: volume, treble/bass, mute and perhaps a power button. Except for the USB hardware, USB Audio speakers look just like the average set of computer speakers.

The Good

USB Audio is very consumer oriented ... the ultimate form of Plug and Play. Anybody who has ever worked technical support can understand the perils of walking an average "home computer user" through any hardware installation. Computer manufacturers worship any technology that can be installed without the user actually having to open their computer case, because it greatly reduces the amount of technical support the company has to provide to its customers. As long as the operating system has good USB support, installation is a snap for any level of user.

Assuming the operating system supports USB Audio, installation involves plugging a small rectangle into another small rectangle, pretty darn brainless. Easy to install and they sound good. The audio stays digital all the way down the USB cable, which cuts down on the noise found in an analog signal.

This works great for an emerging market in the Linux world: embedded systems. If you want to build an Internet appliance with an option for MP3 playback, use a USB Audio device. There's no extra hardware required on the mainboard, so the appliance stays small ... and the end-user installation is painless.

The Bad

USB Audio devices do have a few disadvantages compared to a traditional sound card.

  1. FM Synthesis & Wavetable Support: USB Audio devices directly accept digital audio from the host. So any MIDI playback has to be converted to digital audio by some sort of software algorithm on the host side. This takes extra CPU load. A traditional sound card would do some of this work in hardware, reducing the CPU load.
  2. CPU load for USB transactions: A USB transaction does eat a few CPU cycles, so there is a small CPU load associated with using USB Audio. This is negligible on computers over 400 MHz, but would be noticeable on a slower computer ... even more with the CPU load required for decoding MP3 files.
  3. Surround Sound: The USB Audio specification does support surround sound, but in a limited fashion. USB Audio devices can decode Dolby Prologic audio signals, but only if the USB device has an integrated Prologic decoder. Users that want 5.1 surround sound for DVD playback will benefit more from a hardware-based DVD decoder. Gamers who want surround sound will be better off with a high-end sound card.

The Lowdown

USB Audio is best suited for the "end user" who wants to add digital audio to a computer without the need for tools or open expansion slots. Embedded Linux systems can also utilize USB Audio, since it does not require any sound hardware on the system board (keeps the design small).

The "hardcore gamer" will fare better with a good PCI sound with surround sound outputs, keeping every last CPU cycle to render the violent demise of their latest victims. But USB Audio may appeal to users who fear screwdrivers, or wish to add digital audio to a system devoid of expansion capabilities.

Support for USB Audio in the 2.4 kernel provides a painless end-user install experience, assuming the kernel is properly configured. Let's review the steps required to enable USB Audio in the 2.4 kernel.

The Install

Properly enabling USB Audio requires compiling the 2.4 kernel. If you're unfamiliar with compiling the kernel, take a look at Linux.com's 2.4 kernel article for assistance.

There are four main items to be enabled in the kernel configuration menu:

  1. Sound card support
  2. Generic USB support
  3. Proper USB host controller support
  4. USB Audio Support

Sound card support: To enable USB Audio support 'Sound card support' must be enabled in the kernel. This is necessary to allow your USB Audio device to look like a sound card to Linux.
Generic USB support: Under the 'USB Support' category, select 'Support for USB' I suggest you compile this in using the 'y' option, not as a module. If USB is built directly into the kernel, the support is activated at the early stages of kernel loading, so it's available right at boot time. It's also a good idea to enable the 'Preliminary USB Device Filesystem' and 'Verbose USB Debug Messages' for debugging purposes.
Proper USB host controller support: This is critical to making any USB device work. If your USB controller is part of an Intel or VIA motherboard chipset, choose one of the UHCI drivers (pick one or the other). Any other USB controller falls under the OHCI driver, including iMac, SiS, Compaq and add-in PCI card controllers. Again, compile this in using the 'y' option, not as a module (this take more space in the kernel, but USB is support is available right when the kernel loads).
USB Audio Support: Oddly enough, this is enabled by selecting 'USB Audio support' (amazing, ain't it!). This can be selected as a module and loaded on demand, or compiled directly into the kernel (my machine has it compiled in).

Sound Check

After compiling and installing the new kernel, it's time to test the sound. First, mount the Preliminary USB Device Filesystem so you can check and see if the device was detected (only valid if 'Preliminary USB Device Filesystem' was selected in kernel configuration). As root, type the following command:

mount -t usbdevfs none /proc/bus/usb
This creates the directory /proc/bus/usb, which describes your USB configuration.

All detected USB devices are listed in the file /proc/bus/usb/devices (the output is a bit of a kludge, so read this helpful document to translate the format). Your USB Audio device should show up here. If it doesn't, check the kernel configuration ... or make sure the device is plugged in (sorry, but I had to ask).

Sidenote: USB Audio devices generally appear to me a single device with multiple functions, otherwise known as a 'composite device.' One device is USB Audio compliment, and the rest are typically 'Human Interface Devices' (HID): volume control, tone, mute button, etc. Linux properly supports the USB Audio device, but doesn't recognize the buttons properly. . . yet.

The USB device drivers currently loaded are listed in the file /proc/bus/usb/drivers. Make sure the 'audio' driver is present. If you compiled 'USB Audio support' as a module, you might need to load the 'audio.o' module.

If your device was detected and the USB Audio driver is loaded, it's time to make some noise. You can start your favorite MP3 player, or just cat a file to the audio device. Your audio device will be mapped to /dev/audio or /dev/dsp. One warning: the volume of USB Audio isn't controllable by software in most Linux applications. Make sure your speaker volume isn't set to Super Mofo Loud before testing the device. (Trust me, I learned this from a painful experience involving a subwoofer and the 'Sounds of Slashdot' MP3 file.)

Sounds Easy

As far as hardware installations go, USB Audio is one of the most painless Linux experiences I've ever had. My Microsoft speakers worked the first time they were plugged in (louder than planned, but functional). For more information concerning USB under Linux, check out the Linux USB Project and the Linux-USB Device Overview.

Brian Richardson enjoys the fact that Microsoft's USB hardware works so well on his Linux computer. He wonders how long it will take Microsoft to ditch that whole "software business" and focus their energies on being a Linux hardware vendor

   Page 1 of 1