Наши партнеры

Книги по Linux (с отзывами читателей)

Библиотека сайта rus-linux.net

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23. Audio Compact Discs

Audio compact discs can be played on systems that have a CD-ROM drive and sound card installed. You can control playback of an audio CD in all the ways you can with a traditional CD player, except on a Linux system you control playback with software tools on the command line. There are tools for reading the audio data from a CD and writing it to a file (which you can later write to a CD-R disc, or convert to MP3 format).

Tools and techniques for manipulating CD-ROMs (data CDs) are in CD-ROMs.

23.1 Controlling CD Audio  Controlling CD audio.
23.2 Sampling Sound from a CD  Making a sample of an audio CD.
23.3 Writing an Audio CD-R  Writing a CD-R.
23.4 Other Audio CD Applications  More CD tools and applications.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1 Controlling CD Audio

@sf{Debian}: `cdtool'
@sf{WWW}: ftp://jaka.cerl.uiuc.edu/pub/tinsel/

These recipes describe various ways to play audio CDs using the command-line tools found in the `CDTOOL' suite. Other CD audio tools, including X clients, are listed in Other Audio CD Applications.

23.1.1 Playing an Audio CD  Playing an audio CD.
23.1.2 Pausing an Audio CD  Pausing an audio CD.
23.1.3 Stopping an Audio CD  Stopping an audio CD.
23.1.4 Shuffling Audio CD Tracks  Shuffling tracks.
23.1.5 Displaying Information about an Audio CD  Getting information on the current CD.
23.1.6 Ejecting an Audio CD  Ejecting a disc.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1.1 Playing an Audio CD

Use cdplay to play an audio CD in the CD-ROM drive; the sound is output through the speakers connected to the LINE OUT jack on your sound card. (You may need to use the audio mixer to adjust the volume level and other settings; see Adjusting the Audio Controls.)

  • To play an audio CD, type:

    $ cdplay RET

To begin with a particular track, give the number of the track as an argument.

  • To play an audio CD, beginning with the third track, type:

    $ cdplay 3 RET

To end with a particular track, give the number of the track as a second argument.

  • To play an audio CD, beginning with the first track and ending with the fourth track, type:
    $ cdplay 1 4 RET

  • To play only the third track of an audio CD, type:

    $ cdplay 3 3 RET

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1.2 Pausing an Audio CD

Use cdpause to pause audio CD playback.

  • To pause the current CD playback, type:

    $ cdpause RET

Use cdplay to start playback at the point where it was paused; to restart the playback from the beginning, use cdplay with `x' as an argument.

  • To restart a paused CD, type:
    $ cdplay RET

  • To restart a paused CD from the beginning, type:

    $ cdplay x RET

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1.3 Stopping an Audio CD

To stop playback of an audio CD, use cdstop.

  • To stop the current CD playback, type:

    $ cdstop RET

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1.4 Shuffling Audio CD Tracks

Use cdplay with the `shuffle' argument to play the CD tracks in random order.

  • To shuffle CD playback, type:

    $ cdplay shuffle RET

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1.5 Displaying Information about an Audio CD

Use cdinfo to display information about an audio CD, including its play status and track times. With no options, it outputs the play status: `play' if the CD is currently playing, `paused' if the CD is currently on pause, `no-status' if the CD is not playing, and `nodisc' if no disc is in the drive.

  • For the current status of the audio CD in the CD-ROM drive, type:

    $ cdinfo RET

In addition, cdinfo recognizes the following options:

-a Output the absolute disc time.
-r Output the relative track time.
-s Output the play status (the default action).
-t Output the current track.
-v Output all available information: play status, current track, absolute disc time, and relative track time.

To show the lengths of all tracks on an audio CD in a directory-like format, use cdir. This tool will also show titles and artist names, if known, but for this to work, you must set up an audio CD database (see the cdtool man page for details---Reading a Page from the System Manual).

  • To show a list of tracks, type:

    $ cdir RET
    unknown cd - 43:14 in 8 tracks
      5:15.00  1 
      5:50.40  2 
      5:29.08  3 
      3:50.70  4 
      4:17.00  5 
      5:56.15  6 
      7:13.40  7 
      5:19.22  8 

In this example, the CD contains eight tracks, with a total of 43 minutes and 14 seconds play time.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.1.6 Ejecting an Audio CD

Use cdeject to eject the disc in the CD-ROM drive. If the disc is currently playing, play will stop and the disc will eject.

  • To eject a CD, type:

    $ cdeject RET

NOTE: This command will also eject a CD-ROM (data CD), if the CD-ROM is not currently mounted (see section CD-ROMs).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.2 Sampling Sound from a CD

@sf{Debian}: `cdda2wav'
@sf{Debian}: `cdparanoia'
@sf{WWW}: ftp://ftp.gwdg.de/pub/linux/misc/cdda2wav/
@sf{WWW}: http://www.mit.edu/afs/sipb/user/xiphmont/cdparanoia/index.html

Two tools used for sampling (sometimes called "ripping") data from an audio CD are cdda2wav and cdparanoia. Both can retrieve single tracks or entire disks; the former is the archetypal CD audio-sampling tool for Linux, and should be used when speed is more important than sound quality. The latter does various extra checks for the paranoid, and should be used when an absolutely perfect copy is necessary--at the expense of speed. cdda2wav is perfectly capable of creating a digitally perfect audio sample; cdparanoia is useful for when your original CD may have scratches (its scratch detection capability can attempt to "hold sync" across the scratch), or for when you are using a less-than-optimal-quality CD-ROM drive.

With cdda2wav, you specify the track number to be retrieved as an argument to the `-t' option; use `x' to specify a CD-quality retrieval, and give the name of the CD-ROM device with the `-D' option--unless you have multiple CD-ROM drives installed, this is almost certainly going to be `/dev/cdrom'.

By default, files are written as WAV format files; use the `-O' option followed by `cdr' to write the files in CD audio format. `.cdr' files are useful for burning an audio CD containing the files as tracks (discussed in the following section), and `.wav' files are useful for converting to MP3 format (see section Making an MP3 File). You can convert either format to the other at a later time with sox---see Converting Sound Files.

  • To copy track seven of an audio CD to a CD-quality WAV file in the current directory, type:
    $ cdda2wav -t7 -d0 -x -D /dev/cdrom RET

  • To copy all tracks on an audio CD to separate CD-quality CD audio-format files, type:

    $ cdda2wav -D /dev/cdrom -x -O cdr -d0 -B RET

For more reliable sampling, use cdparanoia. Give the range of audio tracks to sample as an argument (with no arguments, it samples the entire disc). Use the `-w' option to specify WAV format output.

  • To sample the third track from a scratched audio CD in the default CD-ROM drive using "paranoid" data verification, and write the output to a WAV format file in the current directory, type:
    $ cdparanoia -w 3-3 RET

  • To sample the entire audio CD using "paranoid" data verification, type:
    $ cdparanoia -w -B RET

  • To sample the entire audio CD using less-than-maximum "paranoid" data verification, without checking for scratches, and saving each song as a separate raw audio-format file in the current directory, type:

    $ cdparanoia -B -Y -X RET

NOTE: Sampling an entire audio CD can use a lot of disk space; most people delete the `.cdr' or `.wav' files as soon as they make MP3s or burn an audio CD-R from the data.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.3 Writing an Audio CD-R

@sf{Debian}: `cdrecord'
@sf{WWW}: http://freshmeat.net/projects/cdrecord/

Use `cdrecord' to write (or "burn") audio files to a blank CD-R disc. You will need a CD-R drive(31) and the audio files must be in CD-DA CD audio format (they usually have a `.cdda' or `.cdr' file name extension).

Specify the CD-R drive with the special `dev' argument, which is given in this form:


where scsibus is the number of the SCSI bus (0 for the primary bus), target is the SCSI target ID (usually a number from 1 to 6), and lun is its LUN number (most always 0).

Use the `speed' argument to set the speed factor for writing data: give `speed=2' to specify double speed or `speed=4' to specify quad speed.

Use the `-dummy' option to run with the drive laser turned off, so no actual burning takes place; this is useful when you are first using a CD-R drive and need to test your configuration to make sure you've got it right. Another useful option is `-v', which gives a more verbose message output.

Give the names of the audio files to burn, in the order that they should appear on the disc, as arguments to the `-audio' option. The files are written in CD-DA CD audio format, and they should contain 16-bit stereo at 44,100 samples/second (the `.cdr' or `.cdda' files meet this criterion).

  • To burn the file `symphony.cdr' to the disc in the CD-R drive whose target ID is 2 on the primary SCSI bus, type:
    $ cdrecord dev=0,2,0 -audio symphony.cdr RET

  • To burn all the files in the current directory ending with a `.cdr' extension at double speed to the CD-R drive whose target ID is 2 on the primary SCSI bus, and give verbose output, type:
    $ cdrecord dev=0,2,0 speed=2 -v -audio *.cdr RET

  • To run a test burn of the file `symphony.cdr' to the disc in the CD-R drive whose target ID is 6 (LUN 1) on the primary SCSI bus, type:

    $ cdrecord dev=0,6,1 -dummy -audio symphony.cdr RET

When you use wildcards for files, as in the second-to-the-last example, the shell expands the files in alphabetical order. To write a group of tracks in a particular order without specifying all of their names as arguments, rename them so that their names begin with numbers that correspond to the order you want to write them in (see section Moving Files and Directories).

For example, if you have the three files `morning-song.cdr', `midday-song.cdr', and `evening-song.cdr', and you want to write them in that order, rename the files to `01-morning-song.cdr', `02-midday-song.cdr', and `03-evening-song.cdr'; otherwise, if you specify them as `*.cdr', the shell will sort their names so that they will be written to CD-R in the order of `evening-song.cdr', `midday-song.cdr', and `morning-song.cdr'---exactly the opposite of what was intended!

To write a disc containing both data and audio tracks, first specify the file for the data track (it should contain a filesystem image in either ISO 9660 or Rock Ridge format), and then follow it with the `-audio' option and the names of the audio tracks to use. The resulting CD-R will be both mountable as a data CD and playable on audio CD players (the first track on the disc, the data track, will be skipped when playing the audio).

  • To burn the data track `band-info' and all the audio tracks in the current directory with a `.cdda' extension to the CD-R drive whose target ID is 2 on the primary SCSI bus, type:

    $ cdrecord dev=0,2,0 band-info -audio *.cdda RET

NOTE: When writing an audio CD, you should have as few processes running as possible. If cdrecord has to pause even momentarily to let the system shuffle other processes, the CD-R could be ruined! For this reason, it is advisable to avoid switching between consoles--or between windows, if running X--during the CD-R burning process.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.4 Other Audio CD Applications

The following table lists some of the other available tools and applications that work on audio compact discs.

dynamic Project Dynamic is a tool for playing samples of audio CDs; it is distinctive in that it can play audio CDs backwards. {@sf{WWW}}: http://www.cse.unsw.edu.au/~flatmax/dynamic/
workbone An interactive CD player that can be used on the console or in X; it allows you to skip forward and backward through tracks as they are playing.
workman A tool for playing audio CDs, with a graphical interface that looks like the front panel of a physical CD player.
xcdroast XCDRoast is a graphical front-end to the cdrecord tool for use in X. {@sf{WWW}}: http://www.xcdroast.org/

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]