Ubuntu に Bluetooth A2DP 接続する備忘録です.Ubuntu に Bluetooth スピーカ等を接続するではなくて,Ubuntu を PC とかスマホの音の出力先にする方なことにご注意ください.
なお,前提として,Ubuntu を以下の通り pulseaudio-bluetooth server として設定できているとしておきます.
Ubuntu Server 18.04 で pulseaudio-bluetooth server 備忘録
Ubuntu Server 18.04 で pulseaudio-bluetooth server 備忘録です.内容としては,以前の記事の続きとなります.Volumio を pulseaudio に対応させることができましたので,ネットワー...
方法は簡単です.単に,
Bluetooth の Discoverable を ON にして,接続したい端末から Ubuntu Server をペアリングし,さらに,Ubuntu の方で接続端末を「信頼」した後に,再度,接続したい端末から Ubuntu Server に接続を行う
だけです.もちろん,ペアリングと「信頼」は最初の1回だけで,次回以降は単に端末から Ubuntu Server を接続しに行けば良いだけになります.
実際の手順
Microsoft Surface Go で実際にやってみた様子は以下の通りです.
まず,ターミナルで bluetooth の Discoverable を ON にします.
[ bluetooth ] # advertise on
[ CHG ] Controller 5C:F9: 38 :AA:AA:AA SupportedInstances: 0x04
[ CHG ] Controller 5C:F9: 38 :AA:AA:AA ActiveInstances: 0x01
Advertising object registered
[ bluetooth ] # discoverable on
Changing discoverable on succeeded
[ CHG ] Controller 5C:F9: 38 :AA:AA:AA Discoverable: yes
bluetoothctl
Agent registered
[bluetooth]# advertise on
[CHG] Controller 5C:F9:38:AA:AA:AA SupportedInstances: 0x04
[CHG] Controller 5C:F9:38:AA:AA:AA ActiveInstances: 0x01
Advertising object registered
Tx Power: off
Name: off
Apperance: off
Discoverable: off
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 5C:F9:38:AA:AA:AA Discoverable: yes
[bluetooth]#
bluetoothctl
Agent registered
[bluetooth]# advertise on
[CHG] Controller 5C:F9:38:AA:AA:AA SupportedInstances: 0x04
[CHG] Controller 5C:F9:38:AA:AA:AA ActiveInstances: 0x01
Advertising object registered
Tx Power: off
Name: off
Apperance: off
Discoverable: off
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 5C:F9:38:AA:AA:AA Discoverable: yes
[bluetooth]#
これで,接続したい端末から Ubuntu Server が発見可能になるのでペアリングします.すると Ubuntu Server の側で以下のような感じで認識されます.
[ bluetooth ] # discoverable on
Changing discoverable on succeeded
[ CHG ] Controller 5C:F9: 38 :AA:AA:AA Discoverable: yes
[ NEW ] Device D8:C4: 97 :AA:AA:AA SURFACEGO
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000110c- 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000110e-0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA Modalias: bluetooth:v0006p0001d0A00
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 00001000 - 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000110a- 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000110c- 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000110e-0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 00001115 - 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000111e-0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 0000111f- 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: 00001200 - 0000 - 1000 - 8000 -00805f9b34fb
[ CHG ] Device D8:C4: 97 :AA:AA:AA UUIDs: c7f94713- 891e-496 a-a0e7-983a0946126e
[ CHG ] Device D8:C4: 97 :AA:AA:AA ServicesResolved: yes
[ CHG ] Device D8:C4: 97 :AA:AA:AA Paired: yes
[ CHG ] Device D8:C4: 97 :AA:AA:AA ServicesResolved: no
[ CHG ] Device D8:C4: 97 :AA:AA:AA Connected: no
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 5C:F9:38:AA:AA:AA Discoverable: yes
[NEW] Device D8:C4:97:AA:AA:AA SURFACEGO
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA Modalias: bluetooth:v0006p0001d0A00
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: c7f94713-891e-496a-a0e7-983a0946126e
[CHG] Device D8:C4:97:AA:AA:AA ServicesResolved: yes
[CHG] Device D8:C4:97:AA:AA:AA Paired: yes
[CHG] Device D8:C4:97:AA:AA:AA ServicesResolved: no
[CHG] Device D8:C4:97:AA:AA:AA Connected: no
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 5C:F9:38:AA:AA:AA Discoverable: yes
[NEW] Device D8:C4:97:AA:AA:AA SURFACEGO
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA Modalias: bluetooth:v0006p0001d0A00
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device D8:C4:97:AA:AA:AA UUIDs: c7f94713-891e-496a-a0e7-983a0946126e
[CHG] Device D8:C4:97:AA:AA:AA ServicesResolved: yes
[CHG] Device D8:C4:97:AA:AA:AA Paired: yes
[CHG] Device D8:C4:97:AA:AA:AA ServicesResolved: no
[CHG] Device D8:C4:97:AA:AA:AA Connected: no
ペアリングされた端末(今回は Surface Go)を Ubuntu Server 側で「信頼」し,再度端末側から接続します.
# trust D8:C4:97:AA:AA:AA
[ CHG ] Device D8:C4: 97 :AA:AA:AA Trusted: yes
Changing D8:C4: 97 :C4:A7: 26 trust succeeded
# trust D8:C4:97:AA:AA:AA
[CHG] Device D8:C4:97:AA:AA:AA Trusted: yes
Changing D8:C4:97:C4:A7:26 trust succeeded
# trust D8:C4:97:AA:AA:AA
[CHG] Device D8:C4:97:AA:AA:AA Trusted: yes
Changing D8:C4:97:C4:A7:26 trust succeeded
端末側の表示が「音楽に接続済み」となったら完了です.実際に,Surface Go で音を鳴らすと,接続先のスピーカーから音が鳴ります.
どのようなコーデックで接続されているのか等は,以下のようにして pacmd コマンドで確かめることができます.
name: < bluez_source. D8_C4_97_C4_A7_26 . a2dp_source >
driver: < module-bluez5-device. c >
flags: HARDWARE DECIBEL_VOLUME LATENCY
volume: front-left: 65536 / 100 % / 0.00 dB, front-right: 65536 / 100 % / 0.00 dB
base volume: 65536 / 100 % / 0.00 dB
current latency: 58.08 ms
sample spec: s32le 2ch 44100Hz
channel map: front-left,front-right
card: 2 < bluez_card. D8_C4_97_C4_A7_26 >
bluetooth. protocol = "a2dp_source"
device. description = "SURFACEGO"
device. string = "D8:C4:97:AA:AA:AA"
bluez. path = "/org/bluez/hci0/dev_D8_C4_97_AA_AA_AA"
bluez. alias = "SURFACEGO"
device. icon_name = "audio-card-bluetooth"
bluetooth. a2dp_codec = "aptX"
unknown-input: Bluetooth Input ( priority 0 , latency offset 0 usec, available: yes )
active port: < unknown-input >
$ pacmd list-sources
3 source(s) available.
index: 0
...
index: 1
...
* index: 2
name: <bluez_source.D8_C4_97_C4_A7_26.a2dp_source>
driver: <module-bluez5-device.c>
flags: HARDWARE DECIBEL_VOLUME LATENCY
state: RUNNING
suspend cause: (none)
priority: 1500
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
base volume: 65536 / 100% / 0.00 dB
volume steps: 65537
muted: no
current latency: 58.08 ms
max rewind: 0 KiB
sample spec: s32le 2ch 44100Hz
channel map: front-left,front-right
ステレオ
used by: 1
linked by: 1
fixed latency: 40.24 ms
card: 2 <bluez_card.D8_C4_97_C4_A7_26>
module: 29
properties:
bluetooth.protocol = "a2dp_source"
device.description = "SURFACEGO"
device.string = "D8:C4:97:AA:AA:AA"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
bluez.path = "/org/bluez/hci0/dev_D8_C4_97_AA_AA_AA"
bluez.class = "0x2a010c"
bluez.alias = "SURFACEGO"
device.icon_name = "audio-card-bluetooth"
bluetooth.a2dp_codec = "aptX"
ports:
unknown-input: Bluetooth Input (priority 0, latency offset 0 usec, available: yes)
properties:
active port: <unknown-input>
$ pacmd list-sources
3 source(s) available.
index: 0
...
index: 1
...
* index: 2
name: <bluez_source.D8_C4_97_C4_A7_26.a2dp_source>
driver: <module-bluez5-device.c>
flags: HARDWARE DECIBEL_VOLUME LATENCY
state: RUNNING
suspend cause: (none)
priority: 1500
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
base volume: 65536 / 100% / 0.00 dB
volume steps: 65537
muted: no
current latency: 58.08 ms
max rewind: 0 KiB
sample spec: s32le 2ch 44100Hz
channel map: front-left,front-right
ステレオ
used by: 1
linked by: 1
fixed latency: 40.24 ms
card: 2 <bluez_card.D8_C4_97_C4_A7_26>
module: 29
properties:
bluetooth.protocol = "a2dp_source"
device.description = "SURFACEGO"
device.string = "D8:C4:97:AA:AA:AA"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
bluez.path = "/org/bluez/hci0/dev_D8_C4_97_AA_AA_AA"
bluez.class = "0x2a010c"
bluez.alias = "SURFACEGO"
device.icon_name = "audio-card-bluetooth"
bluetooth.a2dp_codec = "aptX"
ports:
unknown-input: Bluetooth Input (priority 0, latency offset 0 usec, available: yes)
properties:
active port: <unknown-input>
この例だと見ての通り,apt-X でつながっていることが分かりますし,遅延がどの程度あるのかなども表示されています.
なお,接続コーデックの選択は,出来る限り高音質のものが選ばれているようです.実際,iOS から接続すると AAC で,Android (d-02K) から接続すると apt-X HD で接続されていました.
やってみようと思ったキッカケ
実はこれ,やってみようと思ったキッカケは,Volumio が a2dp 接続に対応したってのを知ったからです.ただし,残念なことにこれ,有料オプションで,MyVolumio Virtuoso(年額$28.99)ユーザーでないと使えません.
なお,MyVolumio Virtuoso の場合は遠隔地からのストリーミングとか Alexsa との接続とかもサポートするようなんで,これらトータルすると決して高いとは言えない価格だとは思いますが,Bluetooth a2dp 接続のためだけだとちょっと躊躇する金額なことは確かです.
と言うことで,せっかく作った Ubuntu Server で出来ると嬉しいなぁ……と思って試してみた訳です.正直,こんな簡単にできるとは思っていませんでした.そして,これが出来るということは,ラズパイゼロ辺りを使えばかなり安価に高音質なコーデックに対応した Bluetooth スピーカーを作れてしまうということで,あと足りないのは GUI の部分だけってことになります(私が個人的に使う分には ssh でログインしてコマンドで操作するで構わないのですけど,一般的にはそうはいかないでしょう).
なお,安定性はいまだイマイチな感じなので,完全に実用的かといわれれば,まだそこまでじゃない.しかし,前回,前々回の記事
Ubuntu と WF-1000XM3 の接続性と音量を改善する備忘録
Ubuntu と WF-1000XM3 の接続性と音量を改善する備忘録です.接続性の改善WF-1000XM3,とっても良いんですが,Ubuntu(Ubuntu 18.04 LTS + pulseaudio-modules-bt 環境)の組み...
Ubuntu で SBC/AAC/LDAC/Headset を切り替える備忘録
Ubuntu で SBC/AAC/LDAC/Headset の別を切り替える備忘録です.Ubuntu で Bluetooth 接続のイヤフォンやスピーカーをつなぐと,望んでいないプロファイルやコーデックで接続されることがあります.これを切り...
と合わせ,ようやく Linux での Bluetooth 音源の取扱には慣れてきたかな……とは思っています.
以上!