Thursday, May 25, 2006

book: Linux Multi Media Hacks

Audio

2.1. Hacks 13–46: Introduction
XMMS, Rhythmbox, amaroK, juK, and others

Hack 13. Mix Your Audio for Perfect Sound
Use the mixer to understand and tweak the different volume levels your sound card provides.
Linux has two different systems for sound, OSS and ALSA
# command line mixer apps
alsamixer

Hack 14. Surround Yourself with Sound
Get theater-quality sound out of your multi-speaker setup.
Under Windows, configuring this is often quite easy, as the soundcard manufacturer usually provides a program to enable surround sound, but no such software exists for Linux, so you need to go a more manual route. This hack will show you how to enable surround sound, test it, and use it with MPlayer [Hack #48].
# testing surround sound
$ wget ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL-testfiles.tgz
$ tar -xvzf Surround-SDL-testfiles.tgz
$ aplay -Dsurround51 chan-id.wav
2.3.3 Movie Watching
$ mplayer dvd://

Hack 15. Play Multiple Sounds at the Same Time
Play audio from multiple sources—even if your sound card doesn't support it.
Although some sound cards can support mixing from multiple sources, many less-expensive cards and those integrated on motherboards don't, so as a result you need to use a sound server.
The default sound server under KDE is aRts, and the default under GNOME is EsounD.


Hack 16. Get MP3 Libraries for Red Hat–Based Distributions
Many people consider MP3 to be a "free" format simply because it doesn't have DRM functionality built-in but, in fact, For the most part, Linux distributions have historically ignored the liability for shipping MP3 decoding libraries—that is, until Red Hat 8. To install MP3 support on Red Hat–based systems, you will first need to add a third-party package repository to your package manager. Although there are several repositories that provide the package you need, for this example, I use the Dag software repository (http://dag.wieers.com/home-made/apt) for everything.

The first step is to add the Dag GPG key to RPM's list of keys. To do this, open a console, become root, and type the following:
# rpm --import http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt

2.5.1. Use Yum

The next step is to add the Dag repository. How you add the Dag repository depends on whether you use yum or up2date to install packages. Fedora and CentOSboth have Yum installed by default for upgrades, while RHEL uses up2date by default. If you use Yum for upgrades, you edit /etc/yum.conf. Below are lines to add to /etc/yum.conf for Fedora, CentOS, and RHEL (if yum is installed):

Add this line if you use Fedora:

[dag]
name=Dag RPM Repository for Fedora Core
baseurl=http://apt.sw.be/fedora/$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
then install the xmms-mp3 package to get MP3 support:
# yum update
# yum install xmms-mp3



Hack 17. Configure Network Sound # play sound over network
In "Mix Your Audio for Perfect Sound" [Hack #13] I discuss how to use EsounD as a sound server to mix sounds from multiple programs for a sound card that supports only one input. One extra feature of EsounD is the ability to send and receive sound over the network. This can be particularly useful if you use programs like VNC over a local network, because you can use audio applications remotely and hear them on your local machine. Plus, in general, it's just pretty cool to be able to send sound around over the network.
greenfly@napoleon:~$ esd -promiscuous -tcp -public -port 16001
greenfly@moses:~$ esdplay --server ="ip_of_server:16001" sample.wav

Now you can start XMMS, mplayer, xine, or any of the EsounD-capable audio players from this terminal and the sound will be sent over the network.



Hack 18. Manage Your Audio with XMMS
XMMS is a classic Linux audio player you can use to easily play a number of different audio file types.
A number of audio players are available under Linux, but XMMS is a classic that you are likely to find available no matter which Linux distribution you use. XMMShas an interface similar to Winamp under Windows and can play most popular audio formats, including MP3, WAV, Ogg Vorbis, and audio CDs, along with many other formats, if you install the proper input plug-in. XMMS supports streaming audio. To add a streaming audio source to the playlist, click Add URL and type in the URL.
The most popular plug-ins can be downloaded directly from http://www.xmms.org plug-ins that let you play MPEG videos

Options
This tab lets you configure most of the common XMMS options you might want to change. One particularly interesting option is the Use real-time priority when available. during heavy CPU load.

Since XMMS can be controlled from the command line, you can also control it remotely or from a script. Simply write a script containing the commands you want to run and schedule it via cron or at. I've used this feature along with aumix to control the volume and create a quick alarm clock. This also means you can control XMMS over ssh—a fun way to play a trick on a co-worker or roommate.

Hack 19. Shuffle Your Music the Smart Way
Use IMMS to weight your music collection based on your listening habits.
IMMS also offers a number of features beyond basic rating. For example, it keeps track of when a song was played last and makes sure the same song does not repeat too often—a common complaint with traditional shuffle-based systems. Moreover, it is able to recognize different versions of the same songs (for example remixes) and treat them as the same song.

Hack 20. Try Rhythmbox
Use Rhythmbox to manage your audio collection much like the iTunes audio player.
Instead of organizing your collection by directory path, Rhythmbox organizes your collection based on the ID3 tags it finds in your MP3s or Oggs, so you can quickly build collections or find songs based on the artist or album.


Hack 21. Let amaroK Rock Your Music Collection
Use amaroK to integrate great music features such as album art, Audioscrobbler, Musicbrainz, song lyrics, and great playlist management into one application.

As more people have started listening to their music collections on their computers, a number of Internet services have appeared to help manage collections and to utilize all this great metadata that exists on MP3s. The services have ranged from CDDB and FreeDB, which provide album and track information based on CD signatures, to services that provide album art and lyrics. A number of the music players under Linux have utilized one or two of these types of services either natively or through the use of plugins, but the amaroK music player seems to be one of the best at integrating them all by default into a useful and powerful interface. In this hack, I discuss many of the different features of the amaroK player and how to get the most out of them.

This window is split into two main sections—a playlist on the right and a series of tabs along the left that open into a sidebar and display a number of different context-sensitive information panels. This sidebar is where the real power of amaroK lies, and I will talk more about it in a minute. The playlist section is like most other playlist sections for media players and displays title, artist, album, and other metadata that amaroK has scanned from your music.

ou can change artist, title, and other information about the track manually or click Fill-In Tags Using MusicBrainz to take advantage of amaroK's MusicBrainz integration. MusicBrainz compares an audio signature from your track with its own database of signatures and provides you with a list of songs it thinks the track might be

he engine display is where configuration can get a bit complicated. amaroK itself doesn't know how to play MP3s, Oggs, and so on, and instead uses various audio engines that do. This makes amaroK very flexible in that it can adapt to a number of audio engines to suit its environment. Audio engines include the xine engine, GStreamer, aRts, and others.

Finally, the Scrobbler display will allow you to configure an Audioscrobbler account if you wish to submit your listening data to Audioscrobbler. Audioscrobbler is an Internet service through which subscribers upload their listening habits.

The real usefulness of amaroK comes into play in the sidebar. Album art & lyrics

If you are connected to the Internet, the next section of this pane will display a list of suggested songs based on the current track using Audioscrobbler. With Audioscrobbler support enabled, amaroK will grab a list of suggested tracks from Audioscrobbler based on the track you are currently listening to, and display the tracks you happen to have in your collection, sorted by your ranking



Hack 24. Rip CDs from the Command Line
Use command-line tools to rip CDs the old-school way.
There are a lot of CD-ripper and MP3-and Ogg Vorbis–encoder GUI programs out there nowadays that streamline and automate the process of turning a CD into a directory of digital music files. The first step to convert a CD into MP3 or Ogg files is to rip the CDDA audio tracks from the CD to individual WAV files. My tool of choice for this is cdparanoia,
$ cdparanoia -B # to WAV files
$ cdparanoia -B 2-5 # range of tracks

2.13.2. Encode the WAVs to MP3s
choose an MP3 encoder.
the most common encoder under Linux is LAME
http://www.mp3dev.org.
LAME is only distributed in source code form from the web site
$ lame track01.cdda.wav track01.cdda.mp3
By default, LAME encodes in 128 kilobits per second at a Constant Bit Rate (CBR). This means that each second of audio will use 128 kilobits of disk space. For many people, the default is rather low, so you will likely want to use the -b option to specify your own bitrate. To double the bitrate to 256 kilobytes type:
$ lame -b 256 track01.cdda.wav track01.cdda.mp3
LAME also supports Variable Bit Rate (VBR) encoding
$ lame -b 128 -B 256 --vbr-new track01.cdda.wav track01.cdda.mp3

2.13.3. Encode the WAVs to Ogg Vorbis
ompletely open source compressed audio codec to replace MP3
because it is not encumbered with any patents, most distributions also ship with Ogg Vorbis plug-ins, encoders, and other software.
$ oggenc -b 256 track01.cdda.wav



Hack 25. Rip CDs Straight from Konqueror

The Konqueror file manager provides an incredibly easy-to-use CD-ripping program—just drag and drop files from the CD to convert them on the fly to MP3, Ogg, or FLAC.

Some people like to claim that almost everything under Linux (particularly when it comes to multimedia) is far too difficult. However, I think that after trying this next hack, even skeptics will agree that ripping a CD from KDE is about as easy as you can get.



Hack 26. Get a Grip on CD Ripping

Use the Grip program to automate all of your CD ripping tasks.

The command line is definitely a powerful tool, particularly for automation, but it can also make doing some tasks, like ripping a CD, more trouble than it's worth, especially if you plan on tagging the resulting audio with metadata such as ID3 tags. While there are several frontends to command-line tools, Grip, in my opinion, is an excellent example of a GUI frontend that balances the power and configurability of the command line, with the ease of use of a GUI interface. After you get to the end of this hack, your CD-ripping process will be so automated that once you start, you won't even have to pick up a mouse.
http://nostatic.org/grip.



Hack 27. Edit ID3v2 Tags from the Command Line

Use the id3v2 tool to update your music tags either manually on the command line or through shell scripts.

If you ever need to hack the metadata in your MP3 files but wish to have more control over the metadata reading/writing process than you get with common GUI tools, the id3v2 tool can help you. Using this tool, you can dump, change, or remove the ID3 tags from any MP3 file
$ id2v3–l"Dr Greenthumb.mp3"
id3v1 tag info for Dr Greenthumb.mp3:
Title : Dr Greenthumb Artist: Cypress Hill
Album : IV Year: , Genre: Unknown (255)


Hack 28. Add Album Art to ID3 Tags

Many MP3 players can display album art for a track if the art is embedded in the ID3 tag. Use the Album Cover Art Downloader tool to automate the process of adding cover art to your MP3s.



Hack 29. Automate Music File Tagging

Why tag your music files one by one? Use the EasyTag program to automate the naming and tagging of your music.

EasyTAG is a utility for viewing and editing tags for MP3, MP2, FLAC, Ogg Vorbis, MusePack, and Monkey's Audio files. Its simple and nice GTK+ interface makes tagging easy whether you're editing tags manually or taking advantage of EasyTAG's automatic tagging. This hack walks you through using EasyTAG to add tags to your audio files.

To get EasyTAG, go to the official EasyTAG download page at http://easytag.sourceforge.net. This page contains packages for most major distributions or, alternatively, you can download and compile it from source. The program depends on the following libraries:

* GTK 2.4
* id3lib to handle MP3 files,
* libogg and libvorbis for Ogg Vorbis files
* libFLAC (along with libogg and libvorbis) for FLAC files


Hack 30. Correct Music Metadata with MusicBrainz

Learn about MusicBrainz and how to use and contribute to the project.

MusicBrainz aims to aggregate the "brainz" of thousands of music lovers to create an open, user-contributed, music encyclopedia. MusicBrainz collects information about the music artists have released and how musical works and musicians relate to one another. In turn, people can use the project along with tools that utilize MusicBrainz (see "Tools that Use MusicBrainz") to add metadata to their audio files and correct the data that is already there.

Today MusicBrainz has more than 100,000 members and information for over 3,000,000 tracks.
http://musicbrainz.org/products/server/download.html

2.19.3. Tools that Use MusicBrainz

The MusicBrainz project released two flagship tagging applications, Picard and pimpmytunes, that are covered in "Clean Music Metadata at the Command Line" [Hack #31] and "Clean Music Metadata with a GUI" [Hack #32] respectively.

The following applications also make use of MusicBrainz for metadata cleanup or audio CD lookup:

* amaroK (http://amarok.kde.org)
* Juk (http://developer.kde.org/~wheeler/juk.html)
* SoundJuicer (http://www.burtonini.com/blog/computers/sound-juicer)
* Zinf (http://zinf.sf.net)

2.19.4. How to Participate
MusicBrainz needs all kinds of help


Hack 31. Clean Music Metadata at the Command Line

Use Lucene-based tagging in MusicBrainz to automagically scan and tag all your MP3s from the command line.

Most people never understand the importance of clean metadata (e.g., ID3 tags) in their music until they shove their haphazard music collection into an iPod. If you have no tags or inconsistent tags in your music collection, it's nearly impossible to really enjoy your shiny new iPod.


Hack 33. Pass the Mic and Record Audio

You don't need a fancy GUI tool to record audio under Linux. Use SoX's rec utility to record audio from your microphone—and do it all from the command line.

Some people might wonder, with all the different graphical audio recording tools out there, why you would want to record sound from the command line. Audacity has everything you need to record, edit, and save audio in a nice interface, and I even cover how to use it to record audio in [Hack #34]. Even with these tools available, there are certain advantages to recording audio from the command line. For one, it's completely scriptable and can be easily scheduled with tools like cron and can be used to create a radio TiVo of sorts. For example, at one point there was a weekly radio show that I sometimes wasn't home to listen to. I wanted to record the broadcast and listen to it later, so I hooked up my computer microphone input with my radio's headphone output and left the radio tuned to that channel. Then I set a cron job to turn up my mic volume with aumix [Hack #13] and then run the recording program. This hack tells you how to use the SoX sound sample translator and its included rec frontend to start recording audio with just a few keystrokes.

The SoX sound sample translator is a very powerful audio editing tool. It not only can convert between a number of audio formats, but it can also modify audio input, adding echoes, fade in and out, and other effects. For this hack, I use a frontend included with SoX called rec, which uses SoX behind the scenes to record audio from your system's microphone.

No comments:

Digg / Technology

Blog Archive