A2DP (Stereo Bluetooth Headset) on Linux

Note: These instructions will eventually be obsolete. This will not work with Bluez 4 or above, included with Ubuntu 8.10+. PulseAudio is also set to get automatic A2DP configuration through a Google SoC project very soon.

Wires are for suckers. In this day and age, wireless headphones are where it's at. While we may not be able to drop the power cord for the time being, we can at least get rid of annoying, east-to-tangle headphone wires by using a Bluetooth headset.

But no, you say, Bluetooth audio sounds horrible. Well my friend, you were probably using a low-quality profile such as HSP. If you want full-quality stereo profile, you want A2DP.

The first requirement is a Bluetooth adapter on your PC or laptop. The second is a Bluetooth headset that supports the A2DP profile, such as the Jabra BT60s headphones. Most earbud headsets don't support A2DP, so you're out of luck if you own one. Finally, you'll need the BlueZ Utils package installed.

Now we're on to the actual setup. A lot of A2DP tutorials out there require you to install some custom system service or do some weird voodoo dance to get them to work. The reference I have found so far has worked every time for me. Most of this is simplified instructions from the BlueZ wiki, so if you are looking for additional setups I suggest you look there after trying this.

Feeling lazy and want me to do this all for you? Well, today is your lucky day. I've made a custom script that will automatically configure it all for you.

a2dp.sh (1.3 KB, Shell Script)
(Paranoid? View all of the scripts that will be installed.)

Simply run it as a normal user and follow all of the steps:
bash a2dp.sh

It will automatically download the connection script and ALSA configuration file to get the job done. All of the scripts will be installed into ~/.a2dp, with an autostart file in ~/.config/autostart.

After you run it, you probably want to use it with a media player. All you need to do is tell your music/video player to use the "bluetooth" output device. Some players, like Audacious and Amarok, let you specify this in their preferences. GStreamer-based applications, like Banshee and Rhythmbox, rely on GStreamer to output to the right device. To do this, a "toggle" script was included with the script above: ~/.a2dp/toggle.sh. To get the most use out of it, add it to your panel.

In GNOME, right-click a blank space and select Add to Panel, then Custom Application Launcher. Fill it in with the settings below. You must use a full path to the script. To see any dialogs, you must have Zenity. It will work without them, but there will be no notification.

To switch to and back from your Bluetooth headphones and speakers, just give it a click:

(Again, for non-GStreamer apps, this step is not required. Just set the ALSA device to "bluetooth" in the player preferences.)

Fire up your favorite music player and enjoy.

AVRCP (Remote Control)


Some headsets may have control buttons, such as pause, next, and rewind. These may work by default on some desktops, but if it doesn't, there is a good chance you don't have uinput enabled. Open the file /etc/modules with root permissions and add the line with uinput at the end. Save the file and reboot, and AVRCP should work.

PulseAudio Volume Manager

With PulseAudio already in Fedora and soon to be in Ubuntu 8.04, it is sure to get even more popularity. But what is so special about it? To many, it just seems like yet another replacement for esound. And while PulseAudio can be dropped right in to replace ESD without problems, it offers so much more.

One big feature is the volume manager. While it doesn't seem to be packaged with the PulseAudio server itself, it can be installed as pavucontrol.

pavucontrol.png

The screenshot above really speaks for itself. With PulseAudio, not only do you have control over the total sound level, but also over each application individually. This is a feature of Windows Vista, but now you can experience it on your Linux or BSD system as long as you use PulseAudio.

Using ffmpeg to convert to MP3

Now we all know we should be using free and open formats like Vorbis for our audio, right? Yeah. Unfortunately, sometimes we are restricted by what some devices will support.

If you've got some tracks in Vorbis, WAV or another format and you want to convert it to MP3 format. Now you can use the open source MP3 library LAME, but it doesn't support quite as many input formats as ffmpeg does.

ffmpeg, for the uninitiated, is a piece of software (and software library) designed for converting all sorts of audio and video from one format to another. Most distributions don't ship it manually and many don't support it, so you may need to enable extra software repositories before installing the ffmpeg package.

Once you've got that, converting an audio file should be pretty easy and works as follows. Remember ffmpeg does take quite a lot as input files, and will detect the input format automatically. In a similar vain, the output format will be automatically determined by the file extension you give, so it makes light work of conversion and avoids lots of confusing command line switches.

A simple audio convert might be:

$ ffmpeg -i file file.mp3

Substitute in your filename, make sure the .mp3 extension is intact in the output filename and a convert should happen. Obviously, doing like this does have the disadvantage of using default settings.

The simplest of these settings to alter would be the bitrate, which determines the output quality. For MP3, a really quick guide would be that 128 kbps is fair quality, 160 kbps is good quality and 192 or above is very good quality.

Setting the bitrate of the output file is also simple, so let's add it to the command:

$ ffmpeg -b 192k -i file file.mp3

Here I set for 192 kbps quality.

This is only a very basic quick starter, but it does show you how easy it is to start converting audio with ffmpeg. If you need more flexibility in your conversion, you may want to switch to a solution like LAME, but for the ease of use and wealth of input formats a well-configured ffmpeg installation can give you, it's well worth a try for your converting needs too.

  1. 1
  2. 2
  3. 3

Sign In

    Enjoy FOSSwire's content? Have it delivered! Subscribe