The Linux MP3 HOWTO By Philip Kerr, phil@websentric.com v1.10, September 1999 This document describes the hardware, software, and procedures needed to encode and play _M_P_3 sound files under Linux. ______________________________________________________________________ Table of Contents 1. Introduction. 2. Copyright of this document. 3. Where to get this document. 4. Acknowledgments. 5. Disclaimer. 6. Hardware Requirements & Performance Issues. 7. Software Requirements. 8. Setting up your system. 8.1 Setting up for Analogue Audio Capture. 8.2 Setting up for CD-ROM Audio Capture. 8.3 Additional Setting up. 9. Encoding from Audio. 10. Encoding from CD-ROM. 11. Playing MP3's. 12. Feedback. ______________________________________________________________________ 11.. IInnttrroodduuccttiioonn.. This document describes the hardware, software and procedures needed to encode and play MP3 sound files under Linux. 22.. CCooppyyrriigghhtt ooff tthhiiss ddooccuummeenntt.. This HOWTO is copyrighted 1999 Philip Kerr. Unless otherwise stated, Linux HOWTO documents are copyrighted by their respective authors. Linux HOWTO documents may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies. Commercial redistribution is allowed and encouraged; however, the author would like to be notified of any such distributions. All translations, derivative works, or aggregate works incorporating any Linux HOWTO documents must be covered under this copyright notice. That is, you may not produce a derivative work from a HOWTO and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the Linux HOWTO co-ordinator at the address given below. In short, we wish to promote dissemination of this information through as many channels as possible. However, we do wish to retain copyright on the HOWTO documents, and would like to be notified of any plans to redistribute the HOWTOs. If you have questions, please contact Tim Bynum, the Linux HOWTO co- ordinator, at _l_i_n_u_x_-_h_o_w_t_o_@_m_e_t_a_l_a_b_._u_n_c_._e_d_u via email. 33.. WWhheerree ttoo ggeett tthhiiss ddooccuummeenntt.. The most recent official version of this document can be obtained from the Linux Documentation Project . 44.. AAcckknnoowwlleeddggmmeennttss.. In writing this HOWTO I have had to draw heavily on the _S_o_u_n_d_-_H_O_W_T_O By Jeff Tranter, and the _S_o_u_n_d_-_P_l_a_y_i_n_g_-_H_O_W_T_O By Yoo C. Chung. Thanks also to the other HOWTO authors whose works I have referenced: _L_i_n_u_x _S_y_s_t_e_m _A_d_m_i_n_i_s_t_r_a_t_o_r_s _G_u_i_d_e By Lars Wirzenius. _L_i_n_u_x _N_e_t_w_o_r_k _A_d_m_i_n_i_s_t_r_a_t_o_r_s _G_u_i_d_e By Olaf Kirch. _M_u_l_t_i _D_i_s_k _S_y_s_t_e_m _T_u_n_i_n_g _H_O_W_T_O By Stein Gjoen. 55.. DDiissccllaaiimmeerr.. Use the information in this document at your own risk. I disavow any potential liability for the contents of this document. Use of the concepts, examples, and/or other content of this document is entirely at your own risk. All copyrights are owned by their owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Naming of particular products or brands should not be seen as endorsements. You are strongly recommended to take a backup of your system before major installation and backups at regular intervals. 66.. HHaarrddwwaarree RReeqquuiirreemmeennttss && PPeerrffoorrmmaannccee IIssssuueess.. Digital Audio processing is a resource intensive task that relies heavily on the processing and I/O capabilities of a system. I would strongly recommend a Pentium class machine as a minimum. If you are going to be encoding from an analogue audio source, a PCI soundcard will give the best results. The I/O performance difference between an ISA and PCI based card is significant, over 132 Mbits/sec for PCI (quote taken from the _P_C_I_-_H_O_W_T_O). Naturally, the better the quality of the soundcard in terms of its signal-to-noise ratio, the better the encoded MP3. I've been using the Soundblaster PCI128 and just switched over to a Soundblaster Live Value; both cards give good audio performance, but the Live has significantly better S/N ratios, good enough for semi-pro audio work. Remember the old data processing maxim:- garbage in - garbage out! When recording analogue audio to a hard disk, more commonly referred to as direct to disk or d2d recording, the performance of the disk, and its interface is critical. If you are using an IDE based based system, mode 4 or UDMA is preferable as they have a semi-decent transfer rate. The ideal solution would be to use a SCSI based system as the drives and interface have far better throughput capabilities, a sustained 5mbits/sec for SCSI 1 through to 80mbits/sec for ultra/wide SCSI. IDE can peak at anything from 8.3 MB/s to 33 MB/s for Ultra-ATA but these speeds are peak, average transfer rates will be slower. If you can find, or afford, an AV SCSI drive, go for it. AV drives have had the read/write head system optimised for continuous data transference; other SCSI and IDE drives normally cannot sustain continuous data transfer as the write head heats up! Naturally a drive that has cache will give more consistent results than one that doesn't, as the cache will act as a buffer if the heads do lift or it cannot handle the throughput. If your drive isn't up to spec, your recording will suffer from dropouts and glitches, where the drive failed to record the signal. If you are recording one-off events, such as live performances invest in a good SCSI based disk system. Another cause of d2d dropouts is a heavily loaded system. Background tasks can cause the system to momentarily glitch. Its recommended to run as few background services as you can, especially networked based services. For more information about setting network services, and startup scripts please refer to the _S_A_G and _N_A_G guides. Virtual memory paging will also cause glitches, so run with as much physical RAM as you can, I'd recommend at least 32 Mb, but you may well need more. For those wanting to extract the most out of their system, optimising the kernel probably wouldn't do any harm either. While the hardware specifications above will give you a decent system to encode audio data, don't discount using older, lower spec kit if that's all you have access to. It'll be a good challenge for a sys-admin to tweak a low-spec system to give good results, and the end result will probably be a happier Linux box. Another important issue is the audio cabling. Cheap, poor quality cables and connectors will result in poor recording quality. If your soundcard has the option to use phono, sometimes referred to as RCA, connectors, use them. Gold plated contacts will also help maintain audio quality, as will keeping audio cables away from data cables as there will be a chance of interference between them. But don't forget, spending a fortune on the best audio cabling will be lost if the rest of the system hasn't been optimised. For encoding mp3's from CD-ROM, the speed or type of drive will determine the time taken to read the raw information from it. A single speed drive will probably be too slow for all but the most patient. Your CD-ROM must be connected to your soundcard, either using the internal connector, or by taking the headphone's output and patching it into the line-in on the soundcard. For detailed instructions on setting up soundcards, now would be an excellent time to read the _S_o_u_n_d_-_H_O_W_T_O. 77.. SSooffttwwaarree RReeqquuiirreemmeennttss.. Converting audio to MP3's is normally a 2 stage process, first the audio is recorded into a WAV format, then the WAV is then converted into an MP3. Depending on what format you wish to encode audio from, CD or direct audio, will determine what software tools you need to produce the WAV file. If you are wanting to encode from audio input, you will need a program that will record from your soundcard's input and save the results in a WAV format. Below are some useful utilities. _W_a_v_r_e_c Wavrec is distributed as part of wavplay, which can be downloaded from:- To convert CD audio data to WAV format, sometimes known as CD ripping: _C_D_D_A_2_W_A_V _C_d_p_a_r_a_n_o_i_a To convert the WAV file, to MP3 format: _B_l_a_d_e_'_s _M_P_3 _E_n_c_o_d_e_r To play the MP3 you will need a player: _X_m_m_s _(_F_o_r_m_e_r_l_y _k_n_o_w_n _a_s _X_1_1_A_m_p_) _X_a_u_d_i_o You may also need a mixer program; Xmixer works well and is included with most distributions. 88.. SSeettttiinngg uupp yyoouurr ssyysstteemm.. This section will describe the basics of setting up your Linux system to record audio from either an analogue or CD-ROM source. I'm basing this section around my Intel based Linux system which is running Redhat 5.2, but should be reasonably distribution neutral. I'll be working on the Sparc platform version shortly. (if you have any success in using this HOWTO on other hardware, please get in touch). Naturally a reasonable prerequisite is a working soundcard. At this point in the HOWTO, I invite you to read the excellent _L_i_n_u_x _S_o_u_n_d _H_O_W_T_O, by Jeff Tranter. After which a good read of the _L_i_n_u_x _S_o_u_n_d _P_l_a_y_i_n_g _H_O_W_T_O, by Yoo C. Chung. Both of the above mentioned HOWTO's cover the details of getting a sound system working under Linux far better than I could. 88..11.. SSeettttiinngg uupp ffoorr AAnnaalloogguuee AAuuddiioo CCaappttuurree.. Firstly, set up your audio. There are a multitude of ways to route audio before it gets to your Linux box, some common ones are: Line out to Line in. Most audio devices have a Line output sockets. Line level is a standard that specifies what voltage and current the audio device will send out. If I remember correctly it is 500mA for domestic and Semi Pro devices, and 750mA for Pro audio devices. I would guess that the standard set for most soundcards will be 500mA, but some of the newer Pro audio may be to the higher standard It shouldn't make too much difference unless you are recording at very high levels. The Line level output is normally used to connect HI-FI equipment to an amplifier, so things such as Tape Decks, Radio Tuners, CD players, DAT machines and Mini-Disc players should connect without problem. Turntables can be more of a problem, see below for more information. You could capture audio from VCR's as well. Most VCR's will either have Line out for sound, or you can Get a Line out from a SCART socket if your VCR has one. Amplifier Tape out to Line in, Line out to Amplifier Tape in. This configuration is essentially replacing a traditional tape recorder connected to your HI-FI amplifier with your Linux system. The Line out to Tape in allows monitoring of the recording levels. Mike to Mike in. The voltages generated by microphones is very much smaller than those used in Line level devices. If you were to plug a Microphone into the Line in, chances are you would never record anything. _W_A_R_N_I_N_G_, _d_o_i_n_g _t_h_e _r_e_v_e_r_s_e_, _p_l_u_g_g_i_n_g _a _L_i_n_e _l_e_v_e_l _d_e_v_i_c_e _i_n_t_o _t_h_e _M_i_c_r_o_p_h_o_n_e _i_n_p_u_t_, _c_a_n _d_a_m_a_g_e _y_o_u_r _s_o_u_n_d_c_a_r_d_!_! Turntable to Mike in. Sadly I've no information on this at the moment. If I remember correctly the turntable should be connected to the Microphone in, it uses a similar mechanism to record sound and has similar low voltages. Music keyboards & synths should be connected to Line in, with guitars connecting to Line in via a DI (Direct Injection, used to convert the signal to Line level) box. Before you plug in anything into your soundcard, make sure the volume levels are turned down to minimum, or if using microphones they are either turned off or away from speakers. 88..22.. SSeettttiinngg uupp ffoorr CCDD--RROOMM AAuuddiioo CCaappttuurree.. Setting up your Linux system to extract audio data from CD-ROM is reasonably straight forward. If you can hear a track playing from your CD-ROM through your speakers or amplifier, connected to your soundcard, then there's a reasonable chance you should be able to record from it. 88..33.. AAddddiittiioonnaall SSeettttiinngg uupp.. Log in as per normal to your system, then using a mixer program set the recording levels that are loud enough to give you a decent recording level, but aren't too loud and distorting. I normally just judge this by ear, after a while you'll get to know what levels are best for your kit. I recommend either turning off all unnecessary services or switching to the single user runlevel, especially when encoding from an audio source. This is to ensure that the bare minimum of services are running and thus minimising system glitches when recording. I've set up a separate SCSI drive, exclusively to record the audio to, which I'll refer to as /mnt/mp3. I've done this mainly for the performance gains in using a SCSI drive. Also, recording onto a dedicated drive, where you are almost certain the head isn't going to suddenly skip to another part of the drive as you are writing audio data to it, is a good thing :) For details on setting up a Linux system with multiple disk drives, a good read of the _M_u_l_t_i_-_D_i_s_k_-_H_O_W_T_O, by Stein Gjoen may be useful. 99.. EEnnccooddiinngg ffrroomm AAuuddiioo.. Firstly, make sure you have enough space on your drive. At CD quality, 44.1 Khz 16 Bit stereo, 1 minute takes nearly 5 Mb. I normally record at DAT quality, which is 48 Khz 16 Bit stereo. Using wavrec I use the following syntax: /usr/local/bin/wavrec -t 60 -s 48000 -S /mnt/mp3/temp.wav The first part is an explicit path to wavrec. The '-t 60' specifies the length of time to record for, in seconds. The third option, -s 48000 refers to the sample rate in bits/sec. (48000 is the rate for DAT, 44100 is CD) The last option is the path to the output file. To see the full set of options, run waverec -help, or see it's man page. This will produce your WAV file Next you will need to encode it into MP3 format. Use bladdenc with the following command line. /usr/local/bin/bladeenc _[_s_o_u_r_c_e _f_i_l_e_] _[_d_e_s_t_i_n_a_t_i_o_n _f_i_l_e_] -br 256000 The -br option sets the bit rate, in this case I've set the rate to the maximum rate of 256k bits/s. The path to bladeenc may also be different on your system to the one I've used in my example. To see the full set of options, run bladeenc -help, actually this is an invalid option, but will display the list of options. 1100.. EEnnccooddiinngg ffrroomm CCDD--RROOMM.. Again, check you will have enough drive space on your system. I've written a very simple Perl script that will rip and encode tracks from a CD. ______________________________________________________________________ #!/usr/bin/perl if ($ARGV[0] ne "") { $count = 1; do { $cdcap = system("cdparanoia", $count, "/mnt/mp3/tmp/cdda.wav"); $track = "$ARGV[1]/track".$count.".mp3"; $benc = system("bladeenc /tmp/cdda.wav $track -br 256000"); $count++; } until $count > $ARGV[0]; exit; } else { print "Usage cdriper [no of tracks] [destination directory]\n\n"; } ______________________________________________________________________ The main lines of interest are _$_c_d_c_a_p _= _s_y_s_t_e_m_(_"_c_d_p_a_r_a_n_o_i_a_"_, _$_c_o_u_n_t_, _"_/_m_n_t_/_m_p_3_/_t_m_p_/_c_d_d_a_._w_a_v_"_)_; This line calls the CD ripper, cdparanoia. Cdparanoia converts raw CD audio data to WAV format. The salient options are $count, which is the number of tracks to rip, and then the path for the outputted WAV file. In my example this will go to a tmp directory on my MP3 SCSI drive. The WAV file is then converted into a MP3 file using Bladeenc. I've written this Perl script in order to rip a CD without having to rip and encode each track, and without having to use the batch mode of Cdparanoia. This cuts down on free disk space needed as Cdparanoia's batch mode will rip the whole disk, and take up anything upto 600 Meg. Please note: The above script is very basic and has nothing fancy, like error checking. Improve at your leisure :) 1111.. PPllaayyiinngg MMPP33''ss.. So, hopefully, you should now have some MP3 files ready to play. The two most popular MP3 players for Linux are Xaudio, and Xmms (formerly known as X11Amp). Links to the homepages of both players can be found in section 7. I've based this HOWTO around my use of xaudio, primarily because I can use it with or without being in X. The program is shareware. Xaudio is a suite of programs, of most interest to us are xaudio and mxaudio. After installing the files onto your system, you have the choice or running either the command line version, xaudio, or the X version mxaudio. Mxaudio has a nice interface, and is straightforward to use. Xaudio's options can be viewed by running the program with the -help option (xaudio -h). To play a track try xaudio track.mp3 To play a whole directory, xaudio *.mp3 Both programs have README files. 1122.. FFeeeeddbbaacckk.. New hardware and software is being released all the time. If you are using newer versions of the hardware and / or software listed within this document, or can add to anything within this area, please send your information for inclusion to _p_h_i_l_@_w_e_b_s_e_n_t_r_i_c_._c_o_m and I'll include it in the next release. Happy MP3'ing!!