8.3. MP3 Audio
Prev | Chapter 8. Multimedia | Next

## 8.3. MP3 Audio

Contributed by Chern Lee.

This section describes some MP3 players available for FreeBSD, how to rip audio CD tracks, and how to encode and decode MP3s.

### 8.3.1. MP3 Players

A popular graphical MP3 player is XMMS. Winamp skins can be used with XMMS since the interface is almost identical to that of Nullsoft's Winamp. XMMS also has native plug-in support.

XMMS can be installed from the `multimedia/xmms` port or package.

XMMS's interface is intuitive, with a playlist, graphic equalizer, and more. Those familiar with Winamp will find XMMS simple to use.

The `audio/mpg123` port provides an alternative, command-line MP3 player.

mpg123 can be run by specifying the sound device and the MP3 file on the command line. Assuming the audio device is `/dev/dsp1.0` and the MP3 file is `Foobar-GreatestHits.mp3`, enter the following to play the file:

`#` `mpg123 -a `/dev/dsp1.0` `Foobar-GreatestHits.mp3`` High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3. Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp. Uses code from various people. See 'README' for more! THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! Playing MPEG stream from Foobar-GreatestHits.mp3 ... MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo

### 8.3.2. Ripping CD Audio Tracks

Before encoding a CD or CD track to MP3, the audio data on the CD must be ripped to the hard drive. This is done by copying the raw CD Digital Audio (CDDA) data to WAV files.

The `cdda2wav` tool, which is installed with the `sysutils/cdrtools` suite, is used for ripping audio information from CDs and the information associated with them.

With the audio CD in the drive, the following command can be issued as `root` to rip an entire CD into individual (per track) WAV files:

`#` `cdda2wav -D `0,1,0` -B`

The `-D `0,1,0`` indicates the SCSI device `0,1,0`, which corresponds to the output of `cdrecord -scanbus`.

cdda2wav will support ATAPI (IDE) CDROM drives. To rip from an IDE drive, specify the device name in place of the SCSI unit numbers. For example, to rip track 7 from an IDE drive:

`#` `cdda2wav -D `/dev/acd0` -t 7`

To rip individual tracks, make use of the `-t` as shown:

`#` `cdda2wav -D `0,1,0` -t 7`

This example rips track seven of the audio CDROM. To rip a range of tracks, such as track one to seven, specify a range:

`#` `cdda2wav -D `0,1,0` -t 1+7`

dd(1) can also be used to extract audio tracks on ATAPI drives, as described in Section 19.5.5, “Duplicating Audio CDs”.

### 8.3.3. Encoding MP3s

Lame is a popular MP3 encoder which can be installed from the `audio/lame` port. Due to licensing restrictions, a package is not available.

The following command will convert the ripped WAV files ``audio01.wav`` to ``audio01.mp3``:

`#` `lame -h -b `128` \ --tt "`Foo Song Title`" \ --ta "`FooBar Artist`" \ --tl "`FooBar Album`" \ --ty "`2001`" \ --tc "`Ripped and encoded by Foo`" \ --tg "`Genre`" \ `audio01.wav audio01.mp3``

128 kbits is a standard MP3 bitrate. The 160 and 192 bitrates provide higher quality. The higher the bitrate, the larger the size of the resulting MP3. `-h` turns on the “higher quality but a little slower” mode. The options beginning with `--t` indicate ID3 tags, which usually contain song information, to be embedded within the MP3 file. Additional encoding options can be found in the lame manual page.

### 8.3.4. Decoding MP3s

In order to burn an audio CD from MP3s, they must first be converted to a non-compressed WAV format. Both XMMS and mpg123 support the output of MP3 to an uncompressed file format.

Writing to Disk in XMMS:

1. Launch XMMS.

2. Right-click the window to bring up the XMMS menu.

3. Select `Preferences` under `Options`.

4. Change the Output Plugin to “Disk Writer Plugin”.

5. Press `Configure`.

6. Enter or browse to a directory to write the uncompressed files to.

7. Load the MP3 file into XMMS as usual, with volume at 100% and EQ settings turned off.

8. Press `Play`. The XMMS will appear as if it is playing the MP3, but no music will be heard. It is actually playing the MP3 to a file.

9. When finished, be sure to set the default Output Plugin back to what it was before in order to listen to MP3s again.

Writing to stdout in mpg123:

- Run `mpg123 -s `audio01.mp3` > `audio01.pcm``

XMMS writes a file in the WAV format, while mpg123 converts the MP3 into raw PCM audio data. Both of these formats can be used with cdrecord to create audio CDs, whereas burncd(8) requires a raw Pulse-Code Modulation (PCM. When using WAV files, there will be a small tick sound at the beginning of each track. This sound is the header of the WAV file. One can remove the header with SoX, which can be installed from the `audio/sox` port or package:

`%` `sox -t wav -r 44100 -s -w -c 2 `track.wav track.raw``

Refer to Section 19.5, “Creating and Using CD Media” for more information on using a CD burner in FreeBSD.

Prev | Up | Next
8.2. Setting Up the Sound Card | Home | 8.4. Video Playback

This, and other documents, can be downloaded from http://ftp.FreeBSD.org/pub/FreeBSD/doc/

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.