July 14,2006

Ubuntu Linux 6.06 使用藍芽耳機

小弟是ubuntu的初學者,在古狗大神的協助下,花了三四天藍芽耳機才終於有聲音了
(可惜立體聲藍芽耳機居然傳來的是斷斷續續的聲音,單音就超大聲XD)

主要參考:
http://bluetooth-alsa.sourceforge.net/
http://www.52cg.com/Training/system/Linux/200601/47428.html
次要參考:
http://cha.homeip.net/blog/archives/2005/08/gnome_bluetooth.html
http://www.chinaunix.net/jh/4/232267.html

藍芽耳機主要的兩種Profiles,單音:Headset Profile;立體音:Advanced Audio Distribution Profile
目前Linux下Bluetooth Stack主要為Affix 和 Bluez,以下使用Bluez



安裝環境:
Ubuntu Linux 6.06
linux kernel:2.6.15-26-386
Broadcom Dongle
Dopod H1 Headset
Motorola HT820 Headset (支援A2DP)


更新所有套件:
# su
# apt-get update;apt-get dist-upgrade

安裝相關的軟體和library:
可以利用 「Synaptic套件管理程式」 或是指令 「apt」安裝以下套件
libtool, cvs, gcc, make
automake 1.7 <== 注意!Bluetooth-Alsa套件一定要用1.7版,如果已經安裝其他版本,請先移除
bluez-cups, bluez-hcidump, bluez-pcmcia-support, bluez-pin, bluez-utils,
libbluetooth1, libbluetooth1-dev
libasound2, libasound2-dev
gnome-bluetooth
ld10k1, liblo10k1-0, liblo10k1-dev <== ALSA emu10k1/2 patch loader 不確定是否要裝
bluez-btsco
bum <== services管理軟體

設定藍芽的配置檔:
設定修改以下檔案記得先備份,不要鐵齒不會發生意外。要切換到root管理員才能存檔

/etc/bluetooth/pin
藍芽裝置配對時,個人識別碼(安全密碼),設定檔,預設是1234
如果設定值,很詭異的又不會以檔案設的值回應給其他裝置
所以我們要把它檔案內容清空,要不然bluez-pin(gnome下,輸入pin的對話框)不會起來。

/dev/bluetooth/hcid.conf
以下為修改後的內容:
-------------------------------------------------------------------------------------------------------
#
# HCI daemon configuration file.
#

# HCId options
options {
# Automatically initialize new devices
autoinit yes;

# Security Manager mode
# none - Security manager disabled
# auto - Use local PIN for incoming connections
# user - Always ask user for a PIN
#
# 設auto會連不上的裝況出現,設成user每次都輸入,最保險
security user;

# Pairing mode
# none - Pairing disabled
# multi - Allow pairing with already paired devices
# once - Pair once and deny successive attempts
pairing multi;

# PIN helper 作用是在藍芽裝置配時,跳出對話框讓你打密碼
# /usr/bin/pinwrapper只是個link檔,在ubuntu會叫用/usr/bin/bluez-pin
#
#pin_helper /usr/bin/pinwrapper;
pin_helper /usr/bin/bluez-pin;

# D-Bus PIN helper
#dbus_pin_helper;
}

# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "%h-%d";

# Local device class
# 0xff0100
# 接受任何種類的藍芽設備的連接。
# 0x200404
# 是指只接受audio/video device類的設備連接。
# 別台看到你,會變成headset裝置。
# 這個主要用於你有多台藍芽設備時,想控制他們的互相連接時使用.
# 例如你有兩台電腦,一個手機都帶有藍芽,
# 而你只想讓電話連到一台電腦上,就可以使用這種方法來設置。
# 0x3E0100
# ubuntu linux 預設值
class 0xFF0100;

# Default packet type
#pkt_type DH1,DM1,HV1;

# Inquiry and Page scan
iscan enable; pscan enable;

# Default link mode
# none - no specific policy
# accept - always accept incoming connections
# master - become master on incoming connections,
# deny role switch on outgoing connections
lm accept;

# Default link policy
# none - no specific policy
# rswitch - allow role switch
# hold - allow hold mode
# sniff - allow sniff mode
# park - allow park mode
lp rswitch,hold,sniff,park;

# Authentication and Encryption (Security Mode 3)
# 打開驗證驗,減少連不上的情況
auth enable;
#encrypt enable;
}
-------------------------------------------------------------------------------------------------------


安裝藍芽耳機音訊程式:

注意linux 應該使用的是ALSA的音訊系統
前面安裝 bluez-btsco 已經安裝一些應用程式(很像是這樣吧^_^a)

還需要驅動module: snd-bt-sco.ko。
以下為建置程序:
(參考http://bluetooth-alsa.sourceforge.net/)

1. 先到 http://sourceforge.net/projects/bluetooth-alsa 下載完整的source code
2. 把 btsco-0.42.tar.gz 解壓縮,並把解壓縮出來的目錄 btsco-0.42 改名成 btsco
3. 在終端機切換到目錄 btsco 的上一層,
例如btsco放在 /home/user/Deaktop/btsco,
就切換到home/user/Desktop。
4. 用cvs更新source code:
# cvs -d:pserver:anonymous@bluetooth-alsa.cvs.sourceforge.net:/cvsroot/bluetooth-alsa login
要你輸入密碼時,按Enter
# cvs -d:pserver:anonymous@bluetooth-alsa.cvs.sourceforge.net:/cvsroot/bluetooth-alsa co btsco
5. 編譯、安裝檔案:
# su <== 切換換成root 管理員,要不然make install會無權限搬動檔案
# cd btsco
# ./bootstrap
# ./configure <== 記得檢查有沒有這個檔案,如果只是從cvs抓檔案不會有這個檔案。沒有的話回到步驟1
# make
編譯完,我會把btsco整個目錄備份到另一個目錄中,例如/home/user/Desktop/btsco.bak,
因為後來會用到編譯好的檔案,我又找不到他make install後的安裝路徑,只好用此笨方法
# make install
6. 編譯安裝 SCO module:
kernel 需要emu10k1 driver (snd_hwdep_new) ,在前面要求安裝的ALSA emu10k1/2 patch loader
切換到 /home/user/Desktop/btsco/Kernel
# make
# make install <== 會把編譯好的snd-bt-sco.ko安裝到 /lib/modules/2.6.15-26-386/extra/ (看你的核心版本)
7. 重開機或把 Bluetooth services (bluez-utils) 重新啟動
我是用BUM把services重新啟動的笨方法:P

使用藍芽耳機
# modprobe snd_bt_sco
載入完 snd_bt_sco module 後,在 系統 > 偏好設定 > 音效 > 預設音效卡 ,
會多增加 BT Headset,增加一的虛擬的音效卡,也就是/dev/dsp1
# hciconfig hci0 voice 0x0060
把藍芽耳機切換到配對模式
# hcitool scan
掃附近有的藍芽裝置,會列舉出所有藍芽mac adress
# btsco 00:11:22:33:44:55
如果沒有配對過,這時正常會跳出配對的對話框,失敗的話,記得把/etc/bluetooth/pin清空

使用aplay和 arecord測試藍芽耳機
你需要安裝alsaplayer,詳細用法自行man一下
播放:
aplay -D plughw:Headset sound.wav
錄音:
arecord -d 10 -f cd -t wav -D plughw:Headset record.wav

在Skype使用藍芽耳機:
把Handset設成/dev/dsp1即可

Beep Media Player
這個是傳承自XMMS支援Unicode的另一個套件,ubuntu環境都是Unicode,XMMS還是MBCS,會顯示一堆亂碼
BMP Preference > Plugins > Output > Current output plugin
使用 ALSA 0.9.7 output plugin ,在「偏好設定」,Audio device: BT Headset
使用 OSS Output plugin,在「偏好設定」,Audio device: BT SCO PCM(DUPLEX),Mixer device: BT Headset Mixer

其他播放軟體
系統 > 偏好設定 > 音效 > 預設音效卡 設成 BT Headset後正常都可以作用

Stereo (A2DP) Streaming
需要用到先前編譯時產生的 a2play 和 a2recv,安裝mpg321套件
播放:
# mpg123 --au - file.mp3 | ./a2play 00:0D:3C:30:32:AD
不過播放出來會斷斷續續,Bluetooth-alsa官方網頁,上也說不用驚訝 >_<
錄音:
# hciconfig hci0 class 0x200404
# sdptool add A2SNK
# ./a2recv


聲音大小沒有辦法透過「音量控制程式」調整,只能在藍芽耳機上控制大小聲


Posted by yam_opensystem at 樂多Roodo! │13:41 │回應(5)引用(1)linux
樂多分類:網路/3C 共同主題:linux 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/1886167
引用列表:
all about polomurinureon and top news
polomurinureon 94 post【polomurinureon blog】 at October 24,2007 16:53
回應文章
請問一下:

我的PDA沒有Wifi, 只有藍芽, 所以要上網時,
是利用一台有藍芽又可以上網的桌上型電腦, 設定藍芽分享網際網路連線,
如此達成PDA無線上網的目的. 可是我只會在windows上面這樣設定,
http://www.palminfocenter.com/news/8567/howto-bluetooth-internet-with-windows-xp/

請問一下, 如果桌上型電腦跑Linux/Ubuntu, 要用什麼套件/設定來達成這個功能,
做到將internet經由藍芽分享出去呢? 可以給個關鍵詞讓我搜索一下嗎?

謝謝!
Posted by Jack at July 15,2006 02:49
這篇不知道是不是你要的
http://www.iis.sinica.edu.tw/~hus/experience/bluetooth/linux-bluetooth-tcp-ip.html

試試找關鍵字
Affix、Bluez、ICP/IP、網路、藍芽(bluetooth)、PAN(Personal Area Networking Profile)

如果有弄出結果,分享出來吧,順便告訴我一下,謝謝~~
Posted by CL at July 15,2006 18:02
謝謝你這篇文章 ,
給我很大的幫助.

小弟英文很差 , 看英文說明網站太吃力..
Thanks..
Posted by guest at March 11,2008 17:33
[URL=http://www.qeriga.cn/sito-internet-gratis] sito internet gratis [/URL] sito internet gratis [URL=http://www.qeriga.cn/porta-penne] porta penne [/URL] porta penne [URL=http://www.qeriga.cn/fiat-tipo] fiat tipo [/URL] fiat tipo
Posted by Halim at May 21,2008 04:29

你好,我想請問你一下,你在使用a2dp在聽音樂的時候,假設藍芽中斷(不管是電腦中斷或是耳機中斷),正在播放的播放器會當掉嗎??還是就直接由換speaker輸出,因為我最近遇到如果藍芽連線中斷,正在播放的播放器就會當掉,我是用banshee的,所以想請教你使用的情況,謝謝
Posted by 阿欽 at October 17,2008 18:02