11.07.2015 Views

Configuring Linux for a Bluetooth stereo headset - Linux Magazine

Configuring Linux for a Bluetooth stereo headset - Linux Magazine

Configuring Linux for a Bluetooth stereo headset - Linux Magazine

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

COVER STORY<strong>Bluetooth</strong> Headsets<strong>Configuring</strong> <strong>Linux</strong> <strong>for</strong> a <strong>Bluetooth</strong> <strong>stereo</strong> <strong>headset</strong>BLUE SOUNDWe’ll show you how to set up support <strong>for</strong> a <strong>Bluetooth</strong> <strong>stereo</strong> <strong>headset</strong>.BY MARCEL HILZINGERMany <strong>Linux</strong> users enjoy listeningto music through audio playerssuch as XMMS, Amarok, andKaffeine. These players typically outputsound to speakers or headphones attacheddirectly to the computer. If youprefer the headphone option, and if youare the kind of listener who needs roomto dance, you might want to considerusing a wireless <strong>Bluetooth</strong> <strong>headset</strong>.Low-fidelity wireless <strong>headset</strong>s <strong>for</strong> twowayradios and telephones have been onthe market <strong>for</strong> years, but <strong>Bluetooth</strong>basedwireless <strong>stereo</strong> is a more recentphenomenon. Many operating systemsdo not provide built-in support <strong>for</strong> <strong>Bluetooth</strong><strong>stereo</strong>, relying instead on thirdpartytools. <strong>Linux</strong>, on the other hand,really does let you directly configureyour system to support a <strong>Bluetooth</strong><strong>stereo</strong> <strong>headset</strong>.This article is based on the excellentHOWTO <strong>for</strong> Ubuntu [1], although the instructionswill work with any distributionthat has a recent kernel and a <strong>Bluetooth</strong>stack. For more detailed in<strong>for</strong>mation,see the <strong>Bluetooth</strong> ALSA projectpage [2].Mono or Stereo<strong>Bluetooth</strong> supports two profiles <strong>for</strong>transmitting audio signals: SynchronousConnection Oriented (SCO) and AdvancedAudio Distribution Profile(A2DP). The SCO profile defines a bidirectionalconnection with fast response(low latency) <strong>for</strong> voice transmissions.SCO typically uses mono sound quality.The SCO profile lets users send and receivesound at the same time. In contrastto this, the A2DP profile is designed <strong>for</strong>high-quality <strong>stereo</strong> sound. To achievethis higher quality, A2DP uses a unidirectionalconnection with high latency(slow response).A <strong>Bluetooth</strong> <strong>headset</strong> might supportonly SCO, only A2DP, or both profiles.Single-ear <strong>headset</strong>s of the type commonFigure 1: The <strong>Bluetooth</strong> <strong>headset</strong>s by Jabra (left) and Logitech (right) both support <strong>stereo</strong>sound. The Jabra <strong>headset</strong> also supports the mono SCO profile.38 ISSUE 80 JULY 2007 W W W. L I N U X- M A G A Z I N E . C O M


<strong>Bluetooth</strong> HeadsetsCOVER STORYHerbert Matern, Fotolia<strong>for</strong> mobile telephony typically supportjust the SCO profile, whereas <strong>stereo</strong><strong>headset</strong>s often support both. In our lab,I tested the BT620s <strong>stereo</strong> <strong>headset</strong> byJabra and the Wireless Headphones <strong>for</strong>PC by Logitech (Figure 1). The Jabra devicesupports both SCO and A2DP. TheLED flash sequence tells you whichmode the <strong>headset</strong> is working in. TheLogitech <strong>headset</strong> only supports A2DP. Infact, the Logitech <strong>headset</strong> is not officiallya <strong>Bluetooth</strong> device: Logitech sells it witha USB dongle as a normal wireless solution,although the set does have <strong>Bluetooth</strong>capabilities.This article will be concentrating on<strong>stereo</strong> output via the a2dpd daemon.If the approach that uses the A2DPdaemon does not work properly, youmight want to try the old method basedon the snd-bt-sco kernel module. Thissaid, I didn’t experience a single case inwhich snd-bt-sco worked but the A2DPdaemon didn’t.To create the snd-bt-sco.ko kernel module,download the CVS code <strong>for</strong> btscoand sbc, build and install as describedabove, then change directory to btsco/kernel and run the make command. Becomeroot, and copy the module to /lib/modules/Kernelversion/kernel/drivers/bluetooth. Typing uname -a gives youyour Kernelversion.If all of this works, you can load the moduleby typing modprobe snd-bt-sco.The next step is to associate with the<strong>Bluetooth</strong> <strong>headset</strong>. To do so, you need tomake sure the <strong>headset</strong> is in pairingmode. Enter the command line:btsco -r -v Bt-addressMaking sure to replace Bt-address withthe <strong>Bluetooth</strong> address <strong>for</strong> your <strong>headset</strong>.If you see the error messagebtsco v0.42Error: control open (hw:1): UNo such deviceError: Can't find device. Baileither your <strong>headset</strong> is not supported bythe module, or the kernel module mightnot be loaded. If everything works out,you should see the following message:You can refer to the box called “The OldMethod” <strong>for</strong> instructions on the morecomplicated setup <strong>for</strong> a SCO connection.This can be interesting if you would liketo use a <strong>headset</strong> <strong>for</strong> phoning (via Skype,<strong>for</strong> example).For the A2DP daemon, you need thesbc library and the <strong>Bluetooth</strong>-ALSA toolbtsco. See the box titled “DownloadingCode from CVS” <strong>for</strong> details.After unpacking or downloading thesource code, change to the sbc directoryand enter the following commands:The Old Methodbtsco v0.42Device is 1:0Voice setting: 0x0060RFCOMM channel 1 connectedUsing interface hci0Now, pop up a second console and enterthe following command to start the output:mpg123 --au - file.mp3 | Ua2play Bt-addressFor playback, you need to replace file.mp3 with the name of any MP3 file andBt-address with the <strong>Bluetooth</strong> address<strong>for</strong> your <strong>headset</strong>. If you then see themessagesListen thread runningread 2C00C0 2873 times / sec.read 30ABC0 1197 times / sec.read 3061C0 1198 times / sec.read 2FF0C0 1120 times / sec.read 3052C0 1154 times / sec.you can be sure that playback is running.The kernel module approach has a coupleof major disadvantages comparedwith the A2DP daemon. For example,to play a track, you need to enter commandsat the command line – playlistsare not supported – and whenever youupdate the kernel, you will need to installa new module. In addition, playback didnot work at all on the Logitech <strong>headset</strong>because it does not support SCO../bootstrap./configure --prefix=/usrmakesudo make installDepending on your distribution, you willneed to enter either the root password(SUSE, Fedora), or your user password(Ubuntu) to install with a sudo command.When you are done, change directoryto plugz and enter the same commandshere, adding the --sysconfdir=/etc option to the ./configure command:Downloading Code from CVSAfter logging in, you’re prompted to enter your password. Just press Enter.cvs -d:pserver:anonymous@sbc.cvs.source<strong>for</strong>ge.net:/cvsroot/sbc logincvs -d:pserver:anonymous@sbc.cvs.source<strong>for</strong>ge.net:/cvsroot/sbc co sbccvs -d:pserver:anonymous@bluetooth-alsa.cvs.source<strong>for</strong>ge.net:/cvsroot/bluetooth-alsa logincvs -d:pserver:anonymous@bluetooth-alsa.cvs.source<strong>for</strong>ge.net:/cvsroot/bluetooth-alsa co plugzW W W. L I N U X- M A G A Z I N E . C O MISSUE 80 JULY 200739


COVER STORY<strong>Bluetooth</strong> Headsets./bootstrap./configure --prefix=U/usr --sysconfdir=/etcmakesudo make installThis completes the installation. The nextstep is to configure the A2DP daemon.Configuration FilesFor playback, you need to tell the daemonwhich <strong>headset</strong> to use, and you needa .asoundrc file to create a matchingALSA device. If you do not have a.asoundrc file in your home directory,create a new file like so:pcm.a2dpd {type a2dpd}If the file already exists, add the threepreceding lines at the end of the file. Toconfigure the A2DP daemon, copy thesample.a2dprc file called .a2dprc fromthe plugz/also-plugins directory to yourhome directory. Note that both files startwith a dot. Then open the .a2dprc file,remove the pound sign (#) in line 48 toenable the entry #address=00:08:F4:30:07:64, and replace the <strong>Bluetooth</strong>address in this entry with the address <strong>for</strong>your dongle. To find the address, refer tothe next section.<strong>Bluetooth</strong> BasicsTo play music on your <strong>headset</strong>, you needto connect it to your PC. To allow this tohappen, you need to make sure your<strong>headset</strong> is visible. If you have a Jabra<strong>headset</strong>, press the pads on both earphones<strong>for</strong> about five seconds. You cantell that the <strong>headset</strong> is in pairing modebecause the LEDs will alternately flashred, blue, and green.If you have the Logitech <strong>headset</strong>, holddown the button at the center of the leftearphone until the LED starts to flashquickly. Now enter hcitool scan at thecommand line, and you should see the<strong>Bluetooth</strong> address and name of the <strong>headset</strong>s– <strong>for</strong> example:marcel@kim:~> hcitool scanScanning ...00:13:17:70:44:5A Jabra BT620sNow enter this address in the .a2dprc filein your home directory. If the commandfails to find a <strong>Bluetooth</strong> device, eitheryour computer’s <strong>Bluetooth</strong> dongle is notworking or the <strong>headset</strong> is not in pairingmode. To find out whether <strong>Linux</strong> hasdetected the dongle, give the hcitool devcommand. It should display the <strong>Bluetooth</strong>address <strong>for</strong> the dongle.Let’s RockIf you have created the two configurationfiles <strong>for</strong> the ALSA configuration andthe A2DP daemon, you can launch thedaemon at the command line by typinga2dpd. You don’t need to be root to dothis. The following two lines shouldappear as output:avrcp: Accepting Uincoming connectionavdtp: Accepting Uincoming connectionIf you see an error message stating Cannotopen /dev/ input/ uinput: No such fileor directory, you can just ignore it.Leaving the terminal window open,launch XMMS and press Ctrl+P to openthe configuration dialog. As your OutputPlugin, select ALSA [libALSA.so] andthen click on Configure. In the Audiodevice box, manually enter a2dpd (youcan’t select the device from the list), andthen click OK twice to apply the settings.When you startto play back inXMMS, a dialogbox appears,prompting you topair the device.The <strong>headset</strong> mustbe in pairing mode<strong>for</strong> this.On SUSE <strong>Linux</strong>,the pairing dialogappears in theKDE <strong>Bluetooth</strong>framework; onUbuntu, you willsee a Gnome<strong>Bluetooth</strong> dialogbox, assumingyou have installedthe bluez-passkeygnomepackage onEdgy.If pairing worksas intended, theplayer should startto play back. Youwill then see the following message inthe terminal window with the a2dpdcommand:DEBUG: a2dp_transfer_raw: UBandwith: 27250 (212 kbps) 32Instead of XMMS, you could just as easilyuse Amarok or Kaffeine <strong>for</strong> soundoutput. To do so in Amarok, select Settings| Configure Amarok | Audio output,and set the Output module to Alsa. Afterclicking on Apply, enter the a2dpd devicein both the Mono and Stereo boxes(Figure 2).In Kaffeine, select Settings | Xine EngineParameters | Audio, click the ExpertOptions tab, and scroll down until yousee device.alsa_front_device device used<strong>for</strong> <strong>stereo</strong> output. Instead of default,enter a2dpd here.Pros and ConsOne of the biggest advantages of the<strong>Bluetooth</strong> approach compared with legacywireless <strong>headset</strong>s is that you can usea <strong>Bluetooth</strong> <strong>headset</strong> to send commandsto your <strong>Linux</strong> computer. For example,you can stop the player, move to the nexttrack, or backtrack.The .a2dprc file specifies which commandsthe A2DP daemon receives whenyou press a button. In the # AVRCP Com-Figure 2: To be able to play music via the A2DP daemon, you need toset up a2dpd as an ALSA device in Amarok.40 ISSUE 80 JULY 2007 W W W. L I N U X- M A G A Z I N E . C O M


<strong>Bluetooth</strong> HeadsetsCOVER STORYmands to run section, you need to entercommands <strong>for</strong> XMMS. If you preferto use Amarok, replace, <strong>for</strong> example,cmdplay=xmms --play with cmdplay=amarok -p, enter amarok --previous <strong>for</strong>cmdprev=, and so on. In the a2dpdwindow, you will see which commandsthe daemon sends.The same file is used to set the transmissionbandwidth. By default, a2dpduses a maximum of 256Kbps. If youwant to increase the bandwidth, changethe value <strong>for</strong> sbcbitpool from 32 to 64.In our lab, I experienced some dropoutsdoing so. Assessing the value of 16reduces the maximum bandwidth to128Kbps; however, the sound qualityis inferior at this bit rate.Because the <strong>Bluetooth</strong> <strong>headset</strong> automaticallycontacts the A2DP server, youcan develop a configuration to transmitthe stream from one computer to anotherwith some tinkering; this might beuseful if you want to cover the whole ofa large building, <strong>for</strong> example.I wasn’t entirely happy with the soundquality of the <strong>Bluetooth</strong> solution. Althoughthe sound provided by the A2DPprofile was far superior to that of theSCO connection, which is designed<strong>for</strong> voice only, some background noiseclouded what was otherwise a verypositive impression.Some latency issues occurred withsome versions of the daemon. For example,the daemon stopped playing back inan early version from November 7, 2006,if the <strong>headset</strong> was out of range, and thenit played the notes it had missed at doubleor triple speed once the <strong>headset</strong> wasback in range.After applying a patch by Fréderic Dalleau,who is currently continuing the developmentof <strong>Bluetooth</strong>-Alsa in cooperationwith Brad Migley, this problem disappeared.However, the latency problemsoccurred in a CVS version fromNovember 15.This time, the speed wowed and flutteredafter short periods of dropout duringplayback. If you remember the daysof vinyl, you can probably imagine whatthat sounds like. Because of the slow responseof the A2DP connection, theplayer takes about a second to react;however, this is not a genuine issue. Thesolution is not currently recommended<strong>for</strong> video playback: With some video,I only heard the voices, and the soundtrackwas distorted or nonexistent.ConclusionsNow you can enjoy wireless fun with<strong>stereo</strong> sound via <strong>Bluetooth</strong>. It is worthmentioning that <strong>Linux</strong> is a pioneer inthis field. Mac OS-X <strong>Bluetooth</strong> versionsonly support the SCO profile; Appleplans to introduce A2DP sound with itsfuture “Leopard” OS-X release.Windows XP is also behind on tools<strong>for</strong> playing <strong>stereo</strong> sound with <strong>Bluetooth</strong>.Vista needs to resort to a third-partyvendor <strong>for</strong> an A2DP profile. ■INFO[1] Ubuntu <strong>Bluetooth</strong> Audio HOWTO:https:// help. ubuntu. com/ community/<strong>Bluetooth</strong>Audio[2] <strong>Bluetooth</strong> ALSA Project homepage:http:// bluetooth-alsa. source<strong>for</strong>ge. netAdvertisement

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!