Ripping and Encoding Audio Files in Linux

[ Monday, 22 October 2007, qpalzm ]


Listening to the music played back from original audio CDs on a home computer creates clear discomfort — the CD drive is being blocked and the CDs have to be changed again and again (unless you have a home jukebox). Now it’s time we learn to rip (grab) our own audio collection and save it to a hard disk in the form of .mp3, .ogg, or .flac files.

Author: Rafał Topolnicki

Little bit of history

Compact disks have totally dominated the music market, becoming its basic medium of distribution. Those Linux users who have been running Windows systems until now are still accustomed to find .cda files on CDs inserted to CD drives. Mounting the audio CD will result with error messages as the disk does not contain any file system let alone any “files”. Any Audio CD is simply comprised of one stream of a data.

What is CDDA?

Compact Disc Digital Audio format (CDDA) came into being in June 1980 as a result of the collaborative work of Sony and Philips. Their common standard had been described in a specification known to the world as a “Red Book”. It defined the way data should be organized before being written to a disk. For example, using stereo sound, 44.1 kHz sampling, and 16 bit PCM (Pulse Code Modulation) quantization, this translated into 1 s of such a recording would have created a file having the size of 44100 x 16 x 2 = 1411 kb (kilobits). To translate this even further, one minute recording would score 10.6 MB (megabytes) size!

What is PCM?

What is PCM all about? Sound is carried to speakers in an analog form, that means that the electrical signal is in continuous form like sinusoidal line and resembles a function diagram. PCM is a method used to change this electrical signal from an analog form to a digital form. The sampling occurs 44100 times per second in equal time spacings during which the signal is measured with 16 bit resolution for each of the two stereo channels. The higher the samplings, the lower the signal distortions. The basic chunk of data stored on the disk is named a “frame”. It is comprised of 33 bytes from which only 24 bytes carry audio data. Frames are grouped into sectors of 2352 bytes each: 75 sectors are read during one second.

What is ripping?

We’ll begin moving audio files from CD to HDD by ripping. Ripping is a process in which CD contents are being grabbed from the CD and then placed on the hard disk in a raw format. The contents can then be ripped, saving the CD’s logical pattern. This means that you are able to save each song on HDD in a separate file. You will be presented with two rippers, e.g. two software tools designed for this purpose, cdparanoia and cdstatus. They create .raw files, or more often .wav files. Both types of files are of CD quality and exist in an uncompressed format. As a consequence of their raw format, they are big in size. Keeping them in such form would waste our storage resources, so we will convert them to a more space-saving format. WAV against RAW files may store information about their digitization, e.g sampling frequencies and the number of sound channels, as well as what makes their use more economical for any system.

Ripping step by step

To start the ripping you have to know what the audio CD contains, e.g the number of songs, where they start, and were they end, etc. You can issue one of the two commands in cdstatus or cdparanoia, -vsQ. The first ripper needs to be run with additional attributes. Cdstatus –cddb will recognize the contents of the CD first and then will download disk and songs titles from the Compact Disk Database (CDDB), a database that software applications access to lookup audio CD information over the Internet. This is a fairly convenient option if you want to make use of the only two tools, a ripper and a codec (a codec is a device or a program capable of performing encoding and decoding on a digital data stream or signal. The command cdstatus –cddb –rip will grab the contents of the whole CD, saving the songs in .wav files in the current directory (creating an appropriate tree of subdirectories, e.g, performer/cd). In a similar way, this works using cdparanoia -B to make files with trackXX.wav names.

Ripping single songs is a piece of cake as well:

cdstatus --rip --start A --stop B --readchunks 50

where A stands for number of the first song, and B denotes the last song.

Cdstatus reads one frame at a time by default. If the process ends with success it will move to rip another frame. Such work brings poor results in terms of performance. Here comes with the help the –readchunks parameter defining how many frames should be read during one reading process (75 is the maximum number).

In the case of a scratched CD there is the –retries option setting a limit for the ripper to reread the CD data (default=3). Even if the setting didn’t bring satisfying results you might lower the CD speed using the hdparm software tool (which deals with all the system drives and does not belong to “ripping toolkit”).

Favorite songs may be ripped also by cdparanoia. Issuing the command cdparanoia -B — 1-5 you will rip a sequence of songs from first to fifth and will store them in separate files (thanks to -B option). Two minus signs are mandatory. If our interest is restricted to only part of the third song you could use the 3[35] schema which enforces ripping the last 35 seconds of the third song. A somewhat more complex attribute like this one, - -B 2[1:10.30]-5[40], will make cdparanoia save CD data in separate files starting from the second song beginning 1m 10s of its time and 30 frames into the song, then on to the next songs, ending with 40s into the fifth song. More details of this can be found in the application’s manual cdparanoia.

Encoders — the basics

The next step you are to make in moving Audio CDs to HDD involves compression. Compression is either lossless, such as FLAC technology, or lossy, such as MP3 and OGG formats. Compression is aimed at reducing the size of the WAV files. Please keep in mind that when you use lossy encoders you will reduce music quality irreversibly. Lossless technology, due to a lack of popularity, will not be described here in detail.

MP3 - lame

MP3 is decidedly the most commonly used compressed audio standard. Thanks to the high compression ratio achieved without significant loss in sound quality, it has become the main “culprit” in Internet music distribution. Unfortunately, this also includes illegal distribution. LAME (lame) is a lossy encoder. It is used as it is recognized as the best MP3 encoder, providing the best audio quality, processing speed and robust functionality. The reduction in quality stems from the fact that the MP3 standard uses psychoacustic modeling processes. It turns out that the human ear’s sensitivity is variable - it diminishes within the high and the low frequencies. Additionally the louder sound masks the quiet one (having the same frequencies) and while occurring at the same time, a bit later and, hold tight, slightly ahead!

The aforementioned phenomena have led to the invention of MP3 technology in which redundant sounds unheard by human ears were eliminated from the streams of data intended for compression. This process substantially reduced the size of the resulting files. The other main factor which involves the quality of MP3 files, apart from the psychoacustic modeling, is a bitrate, or a throughput, presetting number of bits used to encode 1 second of the audio stream (expressed in kilobits per second - kbps). MP3 supports three types of bitrate - CBR (Constant Bit Rate), VBR (Variable Bit Rate), and ABR (Average Bit Rate).

One second of CBR recordings takes exactly the same amount of memory regardless of what type of music it encodes, being it a pause, a hush, or a fortissimo of the Berlin Philharmonic Orchestra. This mode was commonly used until recently. Today, due to predictability of CBR audio size, it is used to compress movies.

Now let’s turn our attention to VBR. Here you can define only audio quality and the codec itself will automatically choose appropriate bitrate in every moment of its recordings. As a result you will get a considerably better audio quality. It is highly recommended that one learns how to operate the lame encoder as you will make use of its options even within graphical tools. The following command

lame -b 128 file1.wav file1.mp3

will encode file1.wav wave file to mp3 form with CBR set for 128 kbps. For example, 64 kbps or 32 kbps bitrates are intended for voice compression and 96-128 kbps range for files to be played on mobile MP3 players using small earphones. Audio files encoded with 196 kbps bitrate are said to have nearly the same quality as the original audio files.

In most cases the VBR mode will be the better choice than CBR. Agreeing to use VBR, you should simply add the -V n option where n belongs to a number in the range 0 to 9, (where 0 - defines the highest quality, 4 - is default, 9 - means the worst). There are also other options for declaring bitrate: -b and -B which determine the lowest and the highest bitrates respectively. The audio quality can be improved by using the q option (where 0 - the best, 5 - default, 9 - the worst). This parameter deals with psychoacustic analysis directly. You can also use qualitative parameters (not quantitative) like -h which corresponds to -q 2, or -f which is tantamount to -q 7 (f means faster). The best two options of -q 0 and -q 1 are not recommended by the lame authors as the compression times rises twofold, the size of the outcome file by about 10%, and the audio quality is not guaranteed to be better than that achieved by the -h option. Another option is worthy of attention is –noath, which stops encoding sounds lying below the threshold of audibility. Of course, don’t forget to select stereo mode utilizing -m parameter within the lame command. The -m option comes with several flavors:

  • m - mono - good for low bitrate devices and voice encoding
  • s - stereo - default mode (excluding -j option)
  • d - dual channels - full stereo, with every channel encoded separately. Contrary to all expectations, it has an adverse effect on audio quality using constant file size
  • j - joint stereo - stereo encoding method using similarities of the two stereo channels, making lower quality files (it’s default method for VBR greater than 4: -V > 4, or bitrate less than 160 kbps)

Let’s look into the differences between -s and -d options assuming you have 256 kbps audio file. If it is made using stereo mode, the channel throughput distribution can be uneven - 192 kbps for the left channel and 64 kbps for the right channel. This is in strict correlation to the sound complexity on the corresponding channels. Using the dual channel mode, every one of them will gain equal 128 kbps bitrate, even if one of them went silent (played no music).

OGG-Vorbis - oggenc

OGG does not refer to an audio codec as it is commonly thought, but to a multimedia container that was recently invented to pattern and store sounds, movies, and texts. The alternative for MP3 lossy codec is called Vorbis. The Vorbis codec can be a part of the OGG container. The specification was defined by the Xiph.org foundation. It is free of any proprietary patents and this is what distinguish it from MP3, making it very popular in the Open Source world (see texts in Wikipedia). There are also lossless codecs based on OGG technology, e.g. Speedx, that are intended for voice processing and Flac, which is designed for high quality audio recording. The Vorbis codec provides better audio quality than MP3 within bitrate’s lower range of 64 to 128 kbps. As a free dinner doesn’t exist, Vorbis files demand more processing power to play them back. The demand for the electrical power also rises and the result is that the mobile MP3 devices’ working hours shrink a lot. As I said before, MP3 “cuts” the treble to reduce file size. Vorbis does the same but in a slightly less “brute” manner that is shown in the diagrams of their spectrum analyses (intensity/frequency).

The best tool for encoding WAV files to OGG-Vorbis form is the oggenc encoder: this is part of the vorbis-tools package. Issue the following command:

oggenc -b 192 file.wav file.ogg

Although the Vorbis encoder works in VBR mode you are still able to set an arbitrary bitrate number around which coding will take place. You can declare audio quality using the qualitative scale as well. Make use of the -q n option where n belongs to the range of -1 to 10 (default=3). For example - 3 means 96 kbps, 4 corresponds to 128 kbps, and 6 defines 192 kbps. When you resort to -m and -M options you’ll be able to set the minimal and the maximal bitrates respectively.

Both the MP3 and Vorbis technologies allow you to store, within created files, additional data describing processed songs, e.g. the album’s title, music composers, text authors, song titles, etc. See the codecs manuals.

Overview of ripping tools

Making one’s own collection “manually” is tiresome and time-consuming. For this reason a lot of programs were written to ease the tasks. It suffices no to simply to insert an audio disk into the CD drive’s slot and soon you will obtain MP3 or OGG files ready for your use. I will now present a few such tools, both the console-based applications and the graphical tools being written for the GNOME (using the GTK libraries) or the KDE (using the Qt libraries) environment.

Everything’s on your own!

All the needed programs are ready and at hand, now it’s time to glue them together.

$ cdstatus --cddb --rip --other_options
$ cd performer/album
$ for file in *.wav; do oggenc -options $file; done
$ rm *.wav

You might turn to the lame encoder for the job to be done but you would have to get rid of the .wav string from the output filenames:

-options $file ${file%.wav}.mp3

abcde

Well, a truly remarkable ripper! To tell the truth, abcde is a script which delivers full ripping functionality despite its simplicity. What you have to do is to get the sources, satisfy dependencies, install cd-discid (disk identification tool), issue the make install command, and edit the config file, /etc/abcde.conf, which is replete with appropriate comments helping you to understandevery configuration entry. Editing makes sense if you want to rip your own CDs with the same codec, other than default one. Please uncomment following lines:

OGGOPTS='your oggenc options'
ACTIONS='cddb, read, encode, move, clean'
CDROM='your CD drive'
OUTPUTTYPE=ogg
LOWDISK=n ­ make compressions together with rippings
EJECTCD=y


ripperX has a bit old-fashioned
look & feel

The ACTIONS option may be changed according to your fancy. I removed the tag entry as I didn’t need the tags. abcde is worthwhile to run with the V option which generates much more information about the ripping and the compression process. To process only selected files, their numbers need to be passed as parameters to the abcde command. Using ranges is allowable - 1-3 defines the range of 1,2,3 songs. I invite readers to read through the program’s configuration file and the abcde manual (man abcde).

ripperX

It is one of the oldest and certainly one of the best best Linux rippers. Because it is based on GTK libraries, the graphical appearance might scare away some users, however it works wonderfully and is highly configurable. It also supports CDDB. Managing the program is so simple it’d be a waste of time to elaborate more on its functionality.

sound-juicer, Grip

The first program is a ripper which Ubuntu users undoubtedly know the best. It works in a way where everything goes smoothly, easily, and is quite user-friendly, without requiring users to learn the inner workings of the application itself. Perhaps it is the only choice for most Linux users who do not want to read through dozens of manuals, texts, or how-to’s like this one. As far as I am concerned, I was disappointed with this program from the beginning when I decided to change its “advanced” settings - it simply froze: that was all it took.

 
GNOME rippers: Sound-Juicer and Grip alongside

Grip belongs to quite a different breed of rippers. It is decidedly the most complex and advanced from all the rippers described in this document. It enjoys a lot of options, has undergone full localization, contains an intuitive menu, etc. All these features make the use of Grip a true pleasure. Setting tabs facilitates moving between the ripping and the compression tabs. I recommend it to everyone who feels that sound-juicer has unfulfilled their demands, or who can’t stand the ripperX interface.

k3b

At first it was intended to burn CDs but its designers have decided to add the possibility to rip off audio CD and DVDs. Let’s start with CDDB configuration: Settings -< Configure k3b -< CDDB -< Remote -< Enable remote CDDB queries (add http://freedb.org and port:80 if they do not exist), then conform changes followed by Tools -< Rip audio CD selection. K3b should download performer and songs’ titles. Now go to Start, ripping -< File type Ogg (or mp2 lame), configure the encoder, and press the start. As far as KDE is concerned, you may also use another application like Amarok or Konqueror, but it is impossible to describe them all within such limited text.


K3B also can rip audio CDs

Summary

It’s hard to treat the subject about the rippers as complete. Perhaps I will have to come back to the topic to present a more comprehensive instructional on audio compression technologies like mp3, ogg, and flac. For the moment, the knowledge obtained from this article must suffice. So add your newly created files to your playlists and have a nice listen.

This text is based on the article published in Dragonia Magazine, a Polish online magazine about Free and Open-Source Software. You can download the latest Dragonia issue (first one in English from our mirror). The article has been slightly modified compared with the original version by the PolishLinux team.

Translated by P2O2, Proof-read by fgibbs

Subscribe to RSS feed for this article!

5 Comments

fold this thread happy linux guy  Saturday, 27 October 2007 o godz. 1:48 am #  Add karma Subtract karma  +0

it’s just flac, not flack

fold this thread michuk  Saturday, 27 October 2007 o godz. 12:30 pm #  Add karma Subtract karma  +0

Thanks for that, fixed. I know something is wrong with that :)

 
 
fold this thread Maarten Kooiker  Saturday, 27 October 2007 o godz. 10:56 pm #  Add karma Subtract karma  +0

Nice guide,
tomorrow I have some time left, I’ll try to rip some cd’s then. I bookmarked this page!
Cheers,
Maarten

 
fold this thread Grant Johnson  Tuesday, 30 October 2007 o godz. 2:01 am #  Add karma Subtract karma  +0

Vorbis yields significantly better results in VBR mode than in fixed bit rate mode.

 
fold this thread kolya  Tuesday, 28 April 2009 o godz. 2:13 pm #  Add karma Subtract karma  +0

Yeah. Realy good guide!
Thanks!!!

 
Name (required)
E-mail (required - never shown publicly)
URI

Adjust field size: shrink | enlarge)

You can use simple HTML in your comments. Some examples are as follows:
  • A hyperlink: <a href="polishlinux.org">GNU/Linux for everyone!</a>,
  • Strong text: <strong>Strong text</strong>,
  • Italic text: <em>italic text</em>,
  • Strike: <strike>strike</strike>,
  • Code: <code>printf("hello world");</code>,
  • Block quote: <blockquote>Block quote</blockquote>

About the Author

Rafał Topolnicki

Physics student on University of Wrocław, Poland. Interests: GNU/Linux and free software, film and brewery. Writer for Dragonia Magazine, a Polish FLOSS zin.

New AdTaily ads!

Are you a film buff?

film buffs community, movie recommendations and reviews

RSS: Comments

You can follow the comments to this article through a special channel RSS 2.0 .

Related articles: Multimedia

 more »

PolishLinux Top Content

Select distros:

vs

Become our fan on Facebook!

PolishLinux.org on Facebook

Follow PolishLinux on Twitter!

Follow polishlinux on Twitter

Google Ads