Skip to content

Latest commit

 

History

History
144 lines (142 loc) · 4.74 KB

bluetooth-devices.md

File metadata and controls

144 lines (142 loc) · 4.74 KB

RaspberryPi4 - Bluetooth A2DP 接続

Bluetooth デバイスを BlueALSA を使って JACK から直接に扱えるようにする。
ただし、PulseAudio (主に、MASTER ボリュームコントロール)と連動しない。

BlueALSA: Bluetooth Audio ALSA Backend

https://github.com/Arkq/bluez-alsa

Install Required Tools and Essential Development Libraries

# build tools
~ $ sudo apt install automake libtool git build-essential pkg-config python3-docutils
# essential development libraries
~ $ sudo apt install libasound2-dev libbluetooth-dev libdbus-1-dev libglib2.0-dev libsbc-dev
# libraries for profile A2DP codec AAC
~ $ sudo apt install libfdk-aac2 libfdk-aac-dev

Create configure script

~ $ git clone https://github.com/Arkq/bluez-alsa.git
~/bluez-alsa $ autoreconf --install --force

Set configure options

~/bluez-alsa $ mkdir build
~/bluez-alsa/build $ ../configure [OPTION ...]
# --enable-aac:     require libfdk-aac2, libfdk-aac-dev.
# --enable-systemd: none required.
# --enable-cli:     require libdbus-1-3, libdbus-1-dev.

Build & install

~/bluez-alsa/build $ make
~/bluez-alsa/build $ sudo make install

Add groups

~ $ sudo adduser --system --group --no-create-home bluealsa
~ $ sudo adduser --system --group --no-create-home bluealsa-aplay
~ $ sudo adduser bluealsa-aplay audio

Update

~/bluez-alsa $ autoreconf --install --force
~/bluez-alsa/build $ ../configure [OPTION ...]
~/bluez-alsa/build $ make clean
~/bluez-alsa/build $ make
~/bluez-alsa/build $ sudo make install

Uninstall

~/bluez-alsa/build $ sudo make uninstall

Files

type filename
設定 /etc/alsa/conf.d/20-bluealsa.conf
/etc/dbus-1/system.d/bluealsa.conf
systemd /lib/systemd/system/bluealsa.service
/lib/systemd/system/bluealsa-aplay.service
binaries /usr/lib/aarch64-linux-gnu/alsa-lib/*
/usr/bin/bluealsa
/usr/bin/bluealsa-aplay
/usr/bin/bluealsa-cli

設定変更

PulseAudio を Bluetooth デバイスから切り離して、BlueALSA を有効にする。

~ $ sudo apt purge --auto-remove pulseaudio-module-bluetooth
~ $ sudo unlink /etc/alsa/conf.d/99-pulse.conf
~ $ sudo nano /etc/dbus-1/system.d/bluetooth.conf
    </policy>

+   <policy user="bluealsa">
+     <allow send_destination="org.bluez"/>
+   </policy>
+   
  </busconfig>
~ $ sudo nano /etc/asound.conf
+ defaults.bluealsa.codec "aac"
+ pcm.!default pulse
+ ctl.!default pulse
~ $ sudo systemctl enable bluealsa
~ $ sudo systemctl restart bluealsa
(venv) ~AudioWorkstation $ pip install -U git+https://github.com/bluez/pybluez.git

ペアリング

  • Bluetoothデバイスをペアリングモードにする
  • 以下を実行
~ $ sudo bluetoothctl
[bluetooth]# show  # レシーバーの状態確認
[bluetooth]# power on  # "Powered on"にはなるが、"Powered yes"にするには?
[bluetooth]# pairable on
[bluetooth]# scan on -> [▯▯NEW▯▯] Device [device address] [device name]
[bluetooth]# scan off
[bluetooth]# pair [device address]
[[device name]]# paired-devices -> Device [device address] [device name]
[[device name]]# trust [device address]
[[device name]]# connect [device address]
[[device name]]# disconnect
[[device name]]# quit

接続テスト

あらかじめBluetoothデバイスを接続する。

~ $ amixer -D bluealsa:00:00:00:00:00:00 scontrols
# Simple mixer control 'A2DP',0
~ $ jack_control stop
~ $ jack_control exit
~ $ jack_control ds alsa
~ $ jack_control eps realtime True
~ $ jack_control dps duplex True
~ $ jack_control dps device bluealsa:00:00:00:00:00:00
~ $ jack_control dps playback bluealsa:00:00:00:00:00:00
~ $ jack_control dps capture hw:0
~ $ jack_control dps rate 48000
~ $ jack_control dps period 1024
~ $ jack_control dps nperiods 3
~ $ jack_control start
~ $ fluidsynth -jsr 48000 [soundfont file] [midi file]

関連ファイル

  • ~/.asoundrc
  • /etc/asound.conf
  • /etc/alsa/conf.d/20-bluealsa.conf
  • /etc/dbus-1/system.d/bluetooth.conf
  • /etc/dbus-1/system.d/bluealsa.conf
  • /etc/default/bluetooth
  • /etc/default/bluez-alsa
  • /lib/systemd/system/blueatooth.service
  • /lib/systemd/system/blueatooth.target
  • /lib/systemd/system/bluealsa.service
  • /lib/systemd/system/bluealsa-aplay.service
  • /usr/etc/alsa/conf.d
  • /usr/etc/asound.conf

音出しテスト用に使えるWAVファイル

/usr/share/sounds/alsa/Noise.wav
/usr/share/sounds/alsa/Rear_Left.wav
/usr/share/sounds/alsa/Rear_Center.wav
/usr/share/sounds/alsa/Side_Left.wav
/usr/share/sounds/alsa/Front_Center.wav
/usr/share/sounds/alsa/Front_Right.wav
/usr/share/sounds/alsa/Rear_Right.wav
/usr/share/sounds/alsa/Front_Left.wav
/usr/share/sounds/alsa/Side_Right.wav