Converting between File Formats

Converting between File Formats

Sometimes you will run across file formats that haven't been discussed in this chapter. As long as the codecs aren't too new, it's a good bet that SOX will be able to convert these files to a WAV or raw file. SOX automatically does a conversion if you provide different extensions for the input and output files:

 $ sox infile.au outfile.wav 

When dealing with raw files, you need to provide options specifying the number of channels, sample rate, and bit depth just before the file name . The following command line converts mysong.wav into a raw file at CD quality:

 $ sox mysong.wav -r44100 -c2 -sw mysong.raw 

SOX supports a huge variety of PCM file formats. Not to seem repetitive, but you can read the man page or documentation at the SOX homepage for more information.

Newer codecs, such as Windows Media and AAC, are frequency encoded, more similar to MP3 and Vorbis than they are to WAV files. Many of these new codecs are also proprietary and can be read only by certain applications on certain platforms. For this reason, you may have trouble finding a Linux tool to convert these files. It would be most unfortunate if industry pressures cause larger numbers of people to start using these closed formats.

However, MP3 and Vorbis format are still available to everyone. SOX cannot handle frequency-encoded files, so you will need different tools. The Ogg Vorbis distribution includes two command line tools that can be used to convert WAV files into Vorbis files, oggenc and ogg123. To encode a WAV file:

 $ oggenc mysong.wav -b 128 myfile.ogg 

To decode an OGG file:

 $ ogg123 -d wav mysong.ogg 

Now you can play the .ogg files with Ogg's own player or with XMMS.

The popularity of MP3s has spawned a massive number of encoding tools. Many of them are integrated into rippers and provide playlist management, particularly on the Windows side of the fence. Many of these utilities are also asymmetric; they will convert PCM files into MP3s, but not back into WAV or raw files. You'll need to do the latter if you're processing a pre-existing audio clip. One example would be if you clip out a sample from a popular song to use in music made with a loop-based sequencer (see Chapter 20 , Music Production).

bladeenc is a simple command line encoder that can work on multiple files. It is useful for encoding in a background window while you are performing other tasks . As is typical of MP3 encoders, it will encode only WAV or AIFF files. It will support bit rates of 64 through 320 kbps, with a default of 128. As of version 0.93, it does not support variable-bit-rate encoding (which isn't always necessary).

bladeenc is used as follows :

  $ bladeenc -b128 file1.wav file.mp3 file2.wav file2.mp3  

LAME is a more complex encoder that features a pluggable architecture and compiles for many systems other than Linux. It has similar features and syntax to bladeenc, but it also supports variable bit-rate encoding and includes psychoacoustic plug-ins that can squeeze out maximum compression for a given sound quality.

What about decoding MP3s? This can be useful if you want to clip a segment from an MP3 file or apply volume adjustments or effects to it. The file must be uncompressed to perform these operations, but you don't want to play it (yet). Surprisingly, it's harder to find decoders than encoders (at least, decoders that don't just play the audio!). One option that works well is the towav utility that comes with the FreeAmp distribution. If you have the FreeAmp source distribution, you can build it with the following command:

 $ cd freeamp 
 $ make -f Makefile.towav 

The utility takes two arguments, the name of the MP3 file and the name of the WAV file, respectively:

 $ towav infile.mp3 outfile.wav 

XMMS has an output plug-in that will send audio output to a file rather than to the soundcard. You can also use this for decoding any file type that XMMS supports. After the file is decoded, you can process it as desired and re-encode using one of the previously mentioned tools. When decoding a file, remember that the output file will be about 10MB per minute of audio, so make sure you have sufficient disk space.

 



Multitool Linux. Practical Uses for Open Source Software
Multitool Linux: Practical Uses for Open Source Software
ISBN: 0201734206
EAN: 2147483647
Year: 2002
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net