2009年6月10日 星期三

藍芽Speaker,請不要斷續

前一陣子,因為demo需要,和 Jserv去光華商場買了一件藍芽Speaker回來,也開始玩了Bluetooth的a2dp。但運氣不好的是,沒有把bluetooth device 整合好,bluetooth init和開啟時沒有把baud rate設對,以致於經由bluetooth輸出到Speaker時,聲音是斷斷續續,固定間隔的出來。這的確是讓我卡了一陣,雖然解法似乎很簡單。時間差了一點,就可demo出經由a2dp輸出到藍芽Speaker。這讓我感受到資訊整理的重要。

android1.5,已支援a2dp, 經由android的mediaserver 使用 libaudioflinger,再呼叫 liba2dp的function,把解好的聲音檔 (pcm格式) 丟給bluez,做sbc encode,丟到socket,而後送到bluetooth device上。 liba2dp.so為android在bluez裡建立的plugin,這條路是android所提供的。

另一條路,則是build 出bluez 原本給 alsa-lib使用的alsa plugins, libasound_module_ctl_bluetooth.so and libasound_module_pcm_bluetooth.so,
並將其放至/system/usr/lib/alsa-lib/ , here is a quick patch for this.

Some test steps and notes are as below (on Android 1.5, 00:17:53:09:2E:E0 is the device address):
vi /system/etc/asound.conf ,
pcm.bluetooth {
type bluetooth
device 00:17:53:09:2E:E0
profile "auto"
}

test steps:
1. hcitool scan
2. passkey-agent --default --path /org/bluez/hci0 0000 00:17:53:09:2E:E0 &
3. dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0 org.bluez.Adapter.
CreateBonding string:00:17:53:09:2E:E0
4. dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/audio org.bluez.audio.Manager.CreateDevice string:00:17:53:09:2E:E0
5. alsa_aplay -Dplug:bluetooth /horse.wav

除了a2dp, 與Android UI的整合也花了一些功夫,overview的整理一下,SystemSever起來時,會啟動BluetoothDeviceService, BluetoothA2dpService這兩個service。bluetooth 的上層java部份(framework.jar),會透過一層JNI 呼叫 (libandroid_runtime.so),使用dbus與hcid溝通(之後bluez 4.x版為bluetoothd), 以及呼叫libbluedroid來控制硬體。

2009年4月24日 星期五

Use android emulator to play music

試著用android emulator 來播放音樂,

第一步,讓emualtor掛上一個sdcard image,
先使用android sdk裡的 mksdcard 來產生一個image。

$mksdcard 512M sdcard_for_android.so
$emulator -sdcard ./sdcard_for_android.so

接著就是把media file丟進sdcard space, for example
$adb push beat.ogg /sdcard

此時執行Music, 似乎還看不到丟進去的file...?
adb shell 進去,把 system_server 砍掉,讓它重跑。再進去Music,應可看到丟進去的音樂檔。
$ kill 'PID of system_server'

播放,似乎沒有聲音,重新run emulator,這時加入oss audio backend。
$emulator -sdcard ./sdcard_for_android.so -scale 0.5 -audio oss

執行Music,播放.... enjoy the music for a while....


android果然跟平常使用的環境不太一樣啊~~

2009年3月16日 星期一

Take it easy

看似突然,其實不然
按兵不動,一觸即發

早有所悟,擺脫束縛
一切已靜,重回自由

Even I left, I am still a member of the family. Be strong.
I got many friends and partners here.

解脫的感覺很好
咦? 外面的陽光 讚的啦!

2009年3月11日 星期三

Thinking mode

Turning point again. I should react to something as soon as possible and get prepared.

在與team members 聊完後,我需要思考與整理,幸運地還有機會搭上末班捷運,卻因莫名的疏忽,搭錯線,而我已沒有車可以回頭,於是我從古亭站,搭上黃線到景安站,再從景安站走回公司。是的,也許我真的是在思考,這種疏忽並不常發生。從景安站走向新店,路上並沒有什麼吸引到我的注意,除了情趣用品店有幾家,以及薑母鴨以外(稍微地轉移我的注意力)。情趣用品對我來說並不常看到。

也許這就好像,我有個目標,假設是A地(公司),我有路徑B可以到達,也有路徑C可以到達,還有其他路徑我沒辦法走,或是我不知道,但我就是因緣際會地走了路徑C。我並不是因為任何原因而選擇了C路徑,或是只是因為我喜歡C罩杯,(這跟本文一點一點關係也沒有,也許只是稍微回到了高中時期 的寫作風格)。 shit!

走那條路比較好,我無從得知,也許這條路上突然地會讓我遇到正妹,但我想重要的是清楚自己的目標,以及知道我正用我認為對的方法往目標前進。話說回來,其實目標也許有時難以用某樣東西比喻。但目標確認才是能夠使人更能在路上往前進的動力,或是說選擇或轉換了某條路之後,應該要有所期待。

很幸運地,最後回到了公司,比我想像中的還快抵達,還好我能夠走過秀朗大橋,它有小路能讓人和腳踏車通過,不然也許我想我可能會跑在機車道上,那會像是威爾史密思在演全民公敵。


這是個機會,高興的部份。也許我對它還很陌生 :)

2009年2月11日 星期三

一株花草

這株花草(我還不知道叫什麼),今天把它從公司拿回家種到我家的盆栽裡。



原本它是擺在公司的,但我跟溫蒂(Wendy)要了過來!
難得感受一下了種植花草的樂趣! 陽台似乎可成為我心中的巴里島,哈!
的確讓我從工作繁瑣中跳脫出來

期望它可繼續茁壯長大