Bluetooth-alsa

Bluetooth audio for Linux

Overview | History | Future work | Download & build | Credits | Contact us


Things are changing rapidly, so while we occasionally release snapshots of the software, the best route to go is to use the current version from cvs.

Required packages

These differ from distro to distro, but for Ubuntu, the required packages include:

Download and build

install libsbc:

Note: When asking for a password simply press Enter.

cvs -d:pserver:anonymous@sbc.cvs.sourceforge.net:/cvsroot/sbc login 
cvs -d:pserver:anonymous@sbc.cvs.sourceforge.net:/cvsroot/sbc co sbc
cd sbc
./bootstrap
./configure --prefix=/usr
make
sudo make install
install btsco:

cvs -d:pserver:anonymous@bluetooth-alsa.cvs.sourceforge.net:/cvsroot/bluetooth-alsa login 
cvs -d:pserver:anonymous@bluetooth-alsa.cvs.sourceforge.net:/cvsroot/bluetooth-alsa co btsco
cd btsco
./bootstrap
./configure --prefix=/usr --enable-alsaplugin
make
sudo make install

Configure A2DP Driver

This driver allows audio to be sent from an alsa client to a stereo bluetooth headset. The audio is one-way to the set.

Discover the headset's address by doing a bluetooth scan. The headset may need to be in pairing mode for this address to appear:

hcitool scan

The address will look something like 00:14:CF:03:17:8C

cp alsa-plugins/sample.a2dprc ~/.a2dprc

edit ~/.a2dprc to contain the address of your headset on the address= line.

create ~/.asoundrc with simply:

      pcm.a2dpd {
            type a2dpd
      }

and run a2dpd (it's not advised to run it as root). You'll have to arrange for this to be started up subsequently.

You can also have the SDP records for A2DP and AVRCP activated at boot time; this may allow you in some setups to have the headset initiate the connection to a2dpd to start up a stream.

      sdptool add A2SRC
      sdptool add AVRTG

Configure xmms

run xmms, go to prefs (control-p), change output to alsa, click configure, change device from default to a2dpd and select [use software volume control].

If this is a combo headset, turn off your phone first! (Otherwise, the headset will be complicating things by trying to connect to two devices at once)

Turn the headset on in pair mode and hit play in xmms. On the first connect, you should get a popup asking for the pin. Then audio should start.

If your set can do AVRCP, it will be set up to do track advance/pause/stop/play through xmms command-line control. To make AVRCP work with different clients, you'll need to customize ~/.a2dprc.

Configure vlc

This is the only video player I've been able to use with a2dp. You have to edit ~/.vlc/vlcrc and enable the line

alsadev=a2dpd

For some reason the GUI will not allow you to set this device. Also set "Audio Desynchronization Compensation" in the gui to a value between -200 and -600, depending on your headset's latency, to improve audio/video sync.

Configure Kaffeine

If you are using KDE (ex: Kubuntu) you could also use kaffeine to play your multimedia files. In order to do so you need to edit the .kde/share/apps/kaffeine/xine-config file in your home directory. Find the 'audio.driver' parameter and change it to 'alsa'. You also need to change the 'audio.device.alsa_front_device' parameter and change it to 'a2dpd'.

There's a bit of delay between the picture and the voice but it's bearable for me.

Configure SCO (aka mono, aka voice) Driver

This driver will let you do 2-way audio to and from a mono headset. It's called SCO because the transport is Synchronous Connection-Oriented to guarantee low latency.

The old method involves a kernel module and the btsco daemon. See below for the details for this method.

The preferred method uses an outstanding alsa plugin written by Fabien Chevalier instead and requires no kernel patches nor modules. The plugin was installed when you performed the btsco install above.

If you base your .asoundrc on the example alsa-plugins/asound.conf from cvs, you can edit it and add your SCO headset address. Then change the alsa device in xmms to headset and run /usr/bin/headsetd. You should be able to use the headset at this point.

If you subsequently change your .asoundrc, you will have to restart xmms but I don't think you need to restart headsetd.

You will have to set your applications to use the alsa device headset similar to what we did above with a2dpd. Unfortunately some applications won't let you choose this device because they won't let you type in the name of the device and they don't use the extended alsa api for finding alsa plugin devices. At least in the case of vlc, you can edit its configuration directly to get around this.

You will occasionally get static and might even crash if you don't have a kernel patch applied to keep tighter controls on the audio stream. Get the patch here: bluez-sco-flowcontrol-mh7.patch.

Troubleshooting

If you get all kinds of connection refused errors from a2dpd, install bluez-passkey-gnome and reboot so the passkey stuff is working (for some reason it's being left out of some distros).

If that still doesn't help or if you're using KDE, there may be an equivalent kde app or you could try changing pin_helper in /etc/bluetooth/hcid.conf:

pin_helper /usr/bin/bluez-pin;

and restart bluetooth.

If audio is choppy, try putting

lm accept,master;

in hcid.conf. Also note that other bluetooth connections (like getting internet through a cellphone) at the same time you're trying to play music will probably create problems.

Legacy drivers

For the old kernel mod + btsco architecture, you need a kernel with the emu10k1 driver selected (this is one of the drivers that forces the inclusion of the implementation of "snd_hwdep_new"). Build the kernel module:
	cd kernel
	make
	make install
	depmod -e
	make clean
  1. insert the module (or better, set up the alsa configuration to load it)
    	modprobe snd_bt_sco
    
  2. stop the esound controller if it's running via
    	esdctl stop
    
  3. run
            hciconfig hci0 voice 0x0060
    
  4. turn on the headset (you may need to prepare the headset to be paired the computer, usually by turning on the headset and holding the on button until it beeps; make sure the headset has not connected to your cell--this would block the computer's connection.)
  5. run the handler (let it keep running if you run in the foreground)
    	btsco bdaddress
    
  6. You probably need to enter the passkey if it's the first time 'round
  7. send and receive audio from the headset (usually using /dev/dsp1) or via the alsa device with something like
    	aplay -B 1000000 -D plughw:Headset sound.wav
    
Right now the daemon interaction is somewhat limited: Andreas Beck contributed a .btscorc and skype script for making the headset button answer an incoming call. It's in our contrib/ dir and he may have updates here.

Stereo (A2DP) Testing

Only developers should need to use this testing code. The A2DP plugin work is mature enough to use directly.

A2DP provides a way to send stereo high-quality audio to some of the newer headsets. On all the headsets I've seen so far, this is one-way audio, so if you were expecting to get something like a gaming headset (talking to other players, getting stereo sound back from the game), you should wait for the next generation of headsets to get 2-way A2DP.

To test stereo audio without installing the alsa plugin, you can run:

	mpg123 --au - file.mp3 | ./a2play 00:0D:3C:30:32:AD
Where you replace file.mp3 with a good mp3 file and bdaddr with the address of your headset. You can send live audio from line-in etc using a command like:
	./a2play -s -d -r 44100 00:0D:3C:30:32:AD /dev/dsp
Don't be surprised to get a delay. It's probably under 500ms but not much under that.

The A2DP sink code receives a stream from another device. Run it with:

        hciconfig hci0 class 0x200404
	sdptool add A2SNK
	./a2recv
It will try to bind to the bluetooth adapter and send audio out to /dev/dsp.

Embedded status

The status of work on gumstix/xscale is on its own page.

Links