最近买了一个Jabra Bt620s,以前一直以为蓝牙耳机用起来非常简单呢,用了才发现为什么说蓝牙的标准很难执行。
我的本本自带蓝牙,开始用windows XP测试,测试很快就连接上了,密码是0000(在地铁里执行了一下脚本,发现大家的密码几乎都是0000……好像大家都没有修改密码的习惯,由于我不知道如何修改,所以我的密码还是0000^!^,BTW发现现在用蓝牙的人还是很多的,4号线随便一个车厢都有5-6位持有蓝牙设备),但是,听歌的效果简直就是回到了60年代,虽然我那个时候还没出生,不过我也知道60年代的很多耳机的效果都比这个好,《暗算》里面的耳机看上去很值钱的样子。
开始以为我的本子蓝牙适配器不好,后来在网上看了看目前出售的蓝牙适配器,全部都是和U盘一样大小,估计天线都是印刷天线,效果一定不怎么样。我的本子上的蓝牙就这点来说一定不差的。
我用UBUNTU linux,检查了一下自己的蓝牙是否驱动起来:
erjing@erjing-laptop:~$ hciconfig
hci0: Type: USB
BD Address: 00:14:A4:D8:60:5B ACL MTU: 377:10 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:500627 acl:175 sco:0 events:70951 errors:0
TX bytes:33469707 acl:120320 sco:0 commands:41 errors:0
看上去没有问题,hciconfig在源里面就有。hci0就是我的蓝牙适配器了。
新同事很热情,他有一个moto的蓝牙耳机,和他的手机配套,都是moto的。我很好奇,听了一下他的蓝牙耳机的效果--非常不错,就是高音有点刺(后来发现我的也是:~()。我用他的手机放了歌曲,然后用bt620s来接收,发现效果好多了,至少是可以接受的效果。
确定了蓝牙耳机没有问题,就开始在本子上下手。最后好不容易找到了--A2DP!
什么是A2DP?
A2DP is “The Advanced Audio Distribution Profile”,按照字面理解是所谓“高级音频分布配置”,也就是说支持了这个就能让蓝牙耳机支持
“Bluetooth™立体声(A2DP) -支持A2DP Bluetooth™ Profile,用来由手机向耳机及其他装置传送高质量立体声音乐的功能。“
按照我的理解,A2DP因该至少在蓝牙1.2一上才能实现,所以如够你的适配器是1.1的,就很可能没有希望了。如果不支持A2DP,计算机和蓝牙耳机默认通讯的时候只采用8bit的流,晕吧?难怪听上去像收音机。只有驱动了A2DP之后,才能用44000的频率传送。 此外,蓝牙2.0由于速度达到1.8~2.1Mbps,而本生就带stereo编码解码芯片,所以完全可以实现stereo的音频播放。蓝牙1.2只能算支持,但是一旦信号不好了也会很差,所以目前仅仅可以说能支持A2DP,大家如果希望有享受级的,还是要等到2.0完全标准化的时候。就我看来A2DP协议完全是临时性的。
目前,除了需要A2DP驱动之外,不是所有的播放器都支持A2DP功能。就linux来说,xmms,vlc是支持的。
下面是Ubuntu forum上的一篇文章:我直接全部走抄录过来了:
链接:
https://help.ubuntu.com/community/BluetoothAudio
原文:
———————————————————————————————-
BluetoothAudio
Get required packages
Required packages for building these include:
*
build-essential libbluetooth2-dev automake autoconf cvs libtool libasound2-dev xmms
Install Drivers
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 {
o
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.
*
a2dpd
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 [[WWW] http://bluetooth-alsa.sf.net] 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: [WWW] http://bluetooth-alsa.sf.net/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).
If that still doesn’t help or if you’re using kubuntu (?), 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 reboot or run
*
/etc/init.d/bluez-utils restart
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.
———————————————————————————————————-
原文结束。
这里还有:
链接:
http://www.holtmann.org/linux/bluetooth/audio.html
原文
————————————————————————————————————————
Advanced Audio support for the BlueZ stack
by Marcel Holtmann
1. Introduction
The Advanced Audio Distribution Profile (A2DP) is a specification for transfering high quality audio over Bluetooth. Instead of SCO links that are used for telephony applications this specification uses the ACL link as transport. On the lower level the Audio/Video Distribution Transport Protocol (AVDTP) is used for any kind of audio or video streams.
The A2DP defines the low-complexity, subband codec (SBC) as the mandatory codec for all A2DP compatible devices.
2. Toshiba SR-1 information
The Toshiba SR-1 headphone was the first A2DP capable device on the market, but it didn’t get widespreaded to the USA or Europe.
# hcitool inq
Inquiring …
08:00:46:A4:C5:C3 clock offset: 0×6d47 class: 0×200404
# hcitool info 08:00:46:A4:C5:C3
Requesting information …
BD Address: 08:00:46:A4:C5:C3
Device Name: SR-1_1.00
LMP Version: 1.1 (0×1) LMP Subversion: 0×20d
Manufacturer: Cambridge Silicon Radio (10)
Features: 0xff 0xff 0×0f 0×00 0×00 0×00 0×00 0×00
<3-slot packets> <5-slot packets> <encryption> <slot offset>
<timing accuracy> <role switch> <hold mode> <sniff mode>
<park state> <RSSI> <channel quality> <SCO link> <HV2 packets>
<HV3 packets> <u-law log> <A-law log> <CVSD> <paging scheme>
<power control> <transparent SCO>
Besides the mandatory support for the audio sink with the SBC codec it also support another audio sink and an audio source with a non-A2DP codec. This might be used by the voice-regocnition feature of these headphone. The interesting part is the support for content protection and the non-default bitpool range.
< ACL data: handle 0×0028 flags 0×02 dlen 6
L2CAP(d): cid 0×0040 len 2 [psm 25]
AVDTP(s): Discover cmd: transaction 0
> ACL data: handle 0×0028 flags 0×02 dlen 12
L2CAP(d): cid 0×0041 len 8 [psm 25]
AVDTP(s): Discover rsp: transaction 0
ACP SEID 1 - Audio Sink
ACP SEID 3 - Audio Sink
ACP SEID 4 - Audio Source
< ACL data: handle 0×0028 flags 0×02 dlen 7
L2CAP(d): cid 0×0040 len 3 [psm 25]
AVDTP(s): Capabilities cmd: transaction 1
ACP SEID 1
> ACL data: handle 0×0028 flags 0×02 dlen 20
L2CAP(d): cid 0×0041 len 16 [psm 25]
AVDTP(s): Capabilities rsp: transaction 1
Media Transport
Media Codec - SBC
44.1kHz 48kHz
Mono DualChannel Stereo JointStereo
4 8 12 16 Blocks
4 8 Subbands
SNR Loudness
Bitpool Range 4-64
Content Protection
02 00
< ACL data: handle 0×0028 flags 0×02 dlen 7
L2CAP(d): cid 0×0040 len 3 [psm 25]
AVDTP(s): Capabilities cmd: transaction 2
ACP SEID 3
> ACL data: handle 0×0028 flags 0×02 dlen 19
L2CAP(d): cid 0×0041 len 15 [psm 25]
AVDTP(s): Capabilities rsp: transaction 2
Media Transport
Media Codec - non-A2DP
04 00 01 00 01 00 FC
< ACL data: handle 0×0028 flags 0×02 dlen 7
L2CAP(d): cid 0×0040 len 3 [psm 25]
AVDTP(s): Capabilities cmd: transaction 3
ACP SEID 4
> ACL data: handle 0×0028 flags 0×02 dlen 19
L2CAP(d): cid 0×0041 len 15 [psm 25]
AVDTP(s): Capabilities rsp: transaction 3
Media Transport
Media Codec - non-A2DP
04 00 01 00 01 00 FC
Besides this A2DP related support the SDP database of these headphone contains also a record for the headset profile on RFCOMM channel 1 and the audio/video remote control (AVCTP) feature on PSM 23. They also support an unique identifier with an UUID-128 service class saying that it is a TOSHIBA SR-1.
Playing with the Toshiba Bluetooth stack this is getting more weird. To identify the A2DP service on their headphone they don’t use the A2DP sevice record. They look for a special UUID-128 and then display this service as Speech Recognizer SR-1.
> ACL data: handle 0×002a flags 0×02 dlen 31
L2CAP(d): cid 0×0040 len 27 [psm 1]
SDP SS Req: tid 0xda01 len 0×16
pat uuid-128 bc199c24-958b-4cc0-a2cb-fd8a30bf3206
max 0xffff
cont 00
< ACL data: handle 0×002a flags 0×02 dlen 18
L2CAP(d): cid 0×0057 len 14 [psm 1]
SDP SS Rsp: tid 0xda01 len 0×9
tot 0×1 cur 0×1 hndl 0×10000
cont 00
> ACL data: handle 0×002a flags 0×02 dlen 23
L2CAP(d): cid 0×0040 len 19 [psm 1]
SDP SA Req: tid 0xf501 len 0xe
hndl 0×10000
max 0xffe7
aid(s) 0×0000 - 0xffff
cont 00
< ACL data: handle 0×002a flags 0×02 dlen 61
L2CAP(d): cid 0×0057 len 57 [psm 1]
SDP SA Rsp: tid 0xf501 len 0×34
cnt 0×31
aid 0×0000 (SrvRecHndl)
uint 0×10000
aid 0×0001 (SrvClassIDList)
< uuid-128 bc199c24-958b-4cc0-a2cb-fd8a30bf3206 >
aid 0×0100 (SrvName)
str "TOSHIBA SR-1"
cont 00
But their first connection is not to PSM 25 for the AVDTP. They connect to PSM 0×8001 and use a special protocol. A headphone emulation must answer with a specifc sequence of bytes. These values are acknowledged and the stack requests the PIN code after that.
> ACL data: handle 0×002a flags 0×02 dlen 11
L2CAP(d): cid 0×0040 len 7 [psm 32769]
00 01 00 09 01 0D DC
< ACL data: handle 0×002a flags 0×02 dlen 8
L2CAP(d): cid 0×0050 len 4 [psm 32769]
01 01 10 23
< ACL data: handle 0×002a flags 0×02 dlen 15
L2CAP(d): cid 0×0050 len 11 [psm 32769]
01 01 00 09 00 00 00 00 01 33 F4
> ACL data: handle 0×002a flags 0×02 dlen 8
L2CAP(d): cid 0×0040 len 4 [psm 32769]
00 01 21 10
The problem is that it uses an unknown PIN and the default 0000 is not accepted. Setting the headphone emulation into security mode 3 makes at least popup an input box for manual input of a custom PIN and the device setup can proceed. It seems that their special PIN is "fi01B3e5G855". After that a normal AVDTP exchange follows.
3. MusiCool 300 information
The MusiCool 300 from Aiptek is a package that contains two devices, a sending device (Audio SRC) and a receiving device (Headphone). Both of them uses the same Bluetooth chip from GCT and the real manufacturer of these devices is Air2U.
# hcitool info 00:0B:0D:50:0B:10
Requesting information …
BD Address: 00:0B:0D:50:0B:10
Device Name: Audio SRC[0B10]
LMP Version: 1.1 (0×1) LMP Subversion: 0×530
Manufacturer: GCT Semiconductor (45)
Features: 0xff 0xff 0×0d 0×00 0×00 0×00 0×00 0×00
<3-slot packets> <5-slot packets> <encryption> <slot offset>
<timing accuracy> <role switch> <hold mode> <sniff mode>
<park state> <RSSI> <channel quality> <SCO link> <HV2 packets>
<HV3 packets> <u-law log> <A-law log> <CVSD> <power control>
<transparent SCO>
# hcitool info 00:0B:0D:50:12:51
Requesting information …
BD Address: 00:0B:0D:50:12:51
Device Name: Headphone[1251]
LMP Version: 1.1 (0×1) LMP Subversion: 0×530
Manufacturer: GCT Semiconductor (45)
Features: 0xff 0xff 0×0d 0×00 0×00 0×00 0×00 0×00
<3-slot packets> <5-slot packets> <encryption> <slot offset>
<timing accuracy> <role switch> <hold mode> <sniff mode>
<park state> <RSSI> <channel quality> <SCO link> <HV2 packets>
<HV3 packets> <u-law log> <A-law log> <CVSD> <power control>
<transparent SCO>
The Aiptek headphone is an audio sink devices and it uses SBC as default codec for the transmission of high quality audio. All possible settings are supported as required in the specification.
< ACL data: handle 0×002a flags 0×02 dlen 6
L2CAP(d): cid 0×0040 len 2 [psm 25]
AVDTP(s): Discover cmd: transaction 0
> ACL data: handle 0×002a flags 0×02 dlen 8
L2CAP(d): cid 0×0041 len 4 [psm 25]
AVDTP(s): Discover rsp: transaction 0
ACP SEID 1 - Audio Sink
< ACL data: handle 0×002a flags 0×02 dlen 7
L2CAP(d): cid 0×0040 len 3 [psm 25]
AVDTP(s): Capabilities cmd: transaction 1
ACP SEID 1
> ACL data: handle 0×002a flags 0×02 dlen 16
L2CAP(d): cid 0×0041 len 12 [psm 25]
AVDTP(s): Capabilities rsp: transaction 1
Media Transport
Media Codec - SBC
16kHz 32kHz 44.1kHz 48kHz
Mono DualChannel Stereo JointStereo
4 8 12 16 Blocks
4 8 Subbands
SNR Loudness
Bitpool Range 2-250
4. Emulating a headphone
The sending device (Audio SRC) of the Aiptek package has an automatic pairing mode to find the headphone. What it does is searching for a device with the headset class of device 0×200404 and then tries to find an A2DP Sink service record. In the case of BlueZ it is possible to emulate this with the following commands:
# hciconfig hci0 class 0×200404
# hciconfig hci0 class
hci0: Type: USB
BD Address: 00:02:5B:01:00:42 ACL MTU: 384:8 SCO MTU: 64:8
Class: 0×200404
Service Classes: Audio
Device Class: Audio/Video, Device conforms to the Headset profile
# sdptool add a2snk
Audio sink service registered
# sdptool search –bdaddr local a2snk
Searching for a2snk on FF:FF:FF:00:00:00 …
Service Name: Audio Sink
Service RecHandle: 0×10002
Service Class ID List:
"Audio Sink" (0×110b)
Protocol Descriptor List:
"L2CAP" (0×0100)
PSM: 25
"AVDTP" (0×0019)
uint16: 0×100
Profile Descriptor List:
"Advanced Audio" (0×110d)
Version: 0×0100
The details of the record added by the sdptool are not so really important, because the sender device only checks if there is a record for the A2DP Sink service and nothing more. It only checks the existence of this record with a SDP Service Search Request and after a positve response from the BlueZ side with a record handle it starts connecting to the L2CAP channel on PSM 25 for the AVDTP. The hcidump shows the details of the SDP request:
> ACL data: handle 0×002a flags 0×02 dlen 17
L2CAP(d): cid 0×0040 len 13 [psm 1]
SDP SS Req: tid 0xfffe len 0×8
pat uuid-16 0×110b (AudioSink)
max 0×2
cont 00
< ACL data: handle 0×002a flags 0×02 dlen 18
L2CAP(d): cid 0×0040 len 14 [psm 1]
SDP SS Rsp: tid 0xfffe len 0×9
tot 0×1 cur 0×1 hndl 0×10002
cont 00
To proceed further with the headphone emulation there must be a listening L2CAP service on PSM 25. At the moment there exists no program for doing this.
5. Related projects
Bluetooth-alsa Project
6. Product links
Aiptek BT MusiCool 300
BlueTake i-PHONO BT420 EX
7. Qualification links
Toshiba Bluetooth Wireless Speech Recognizer
Air2U Bluetooth Audio adapter MCA01
Air2U Bluetooth Headphone MCH02
————————————————————————————————————————
原文结束.
基本上,看过这两篇就能知道了,在linux下可以用alsa-plugs开放这个功能,我的xmms没有配置出来,不过vlc还是不错,修改了配置以后立刻就能用了。a2dpd需要你自己启动,不要在root模式下用,上面用mpeg123通道的方式测试很危险,建议大家不要用多,因为我的耳机就因此“死机”了…..源里的btsco不要用,如果安装了就删除吧,因为你需要a2dpd,这个默认是不编译的,还有就是上面提到的前提安装包都要安装全了,要不btsco会提示很多找不到的库。配置的时候完全按照这篇手册来,不要被INSTALL里面的误导了。
hcitool等等都可以用源里面的,唯一需要自己编译的只有这个btsco,听歌的时候不用btsco -v XXXXXXXXX来链接耳机,因为a2dpd会自动链接上的。如果觉得不方便,可以把a2dpd放在gnome的启动里面,这样就不用自己手动启动了。如果不按照howto,a2dpd很可能没有编译出来,所以一定要按照howto的编译。
对了,我到现在都没有找到IBM T4x蓝牙的A2DP的驱动,据说有收费驱动。
大家在购买音乐手机的时候一定要注意A2DP功能,如果没有就不能支持蓝牙立体声了。好在现在很多手机都推出了插件来解决,PPC上也有解决的,只需升级一下。