Bluetooth A2DP¶
AD2DP Introduction¶
A2DP stands for Advanced Audio Distribution Profile. This is the Bluetooth Stereo profile which defines how high quality stereo audio can be streamed from one device to another over a Bluetooth connection - for example, music streamed from a mobile phone to wireless headphones.
Although many products may have Bluetooth enabled for voice calls, in order for music to be streamed from one Bluetooth device to another, both devices will need to have this A2DP profile. If both devices to do not contain this profile, you may still be able to connect using a standard Headset or Handsfree profile, however these profiles will not support stereo music.
BlueZ5 configuration currently supports A2DP both in server and client mode.
Please note that to correctly work, both HCI interface and pulseaudio server must be up & running. Please refer to FAQ section for further details
Server Mode¶
In server mode, you can connect the board via BT to a PC or a mobile phone and play an A2DP audio stream using on-board headphones connector.
Playback from external BT source¶
- Connect headphones or speakers to the on-board headphones connector
- Put the external device into pairing mode.
- Make sure the external device is discoverable.
- Scan and connect the external device to Variscite board.
bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# pairable on
[bluetooth]# scan on
Copy mac address
[bluetooth]# scan off
[bluetooth]# pair <mac address>
Approve pairing on the device if required
[bluetooth]# trust <mac address>
[bluetooth]# connect <mac address>
[bluetooth]# quit
- On the client side, connect to the device Variscite and play sound through it.
Recording from external BT source¶
- Follow the steps above to pair and connect with external BT device
- Check cards availability
- If it's not the current profile, switch to a2dp profile
example:
- recording audio originated by external BT source:
Note: The name format of BT device may differ between Yocto versions. Please check the output of pactl list sources short for the exact device name.
Client Mode¶
In client mode, you can connect and play A2DP audio stream using bluetooth headphones.
Prepare the server device¶
Make sure the server device is discoverable.
Connect¶
Into the console of the client device:
- Start utility "bluetoothctl":
example:
bluetoothctl
[NEW] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
[NEW] Device C8:14:79:27:F1:82 SM-T315
[bluetooth]#
- Prepare to сonnection:
example:
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]#
-
The first time only, to connect BT headphones, make sure they are in pairing mode. They need to show up in the scan.
-
Enable scanning
example:
[NEW] Device 68:DF:DD:5D:CF:96 malupas
[NEW] Device 00:06:F7:B3:E9:ED MM100
[NEW] Device 00:07:80:41:68:15 KTS540_0000000
[NEW] Device C8:14:79:27:F1:82 SM-T315
[bluetooth]# scan on
Discovery started
[CHG] Controller F8:DC:7A:07:8D:A6 Discovering: yes
[CHG] Device 00:06:F7:B3:E9:ED RSSI: -57
[CHG] Device 00:07:80:41:68:15 RSSI: -65
[CHG] Device 68:DF:DD:5D:CF:96 RSSI: -98
[CHG] Device 00:07:80:41:68:15 RSSI: -73
"[NEW] Device 00:06:F7:B3:E9:ED MM100" are BT headphones.
- Disable scanning
example:
[bluetooth]# scan off
Discovery stopped
[CHG] Controller F8:DC:7A:07:8D:A6 Discovering: no
[bluetooth]#
- Pair the device
- Connect the device
example:
[bluetooth]# connect 00:06:F7:B3:E9:ED
Attempting to connect to 00:06:F7:B3:E9:ED
[CHG] Device 00:06:F7:B3:E9:ED Connected: yes
Connection successful
[MM100]#
- Trust the device
example:
[MM100]# trust 00:06:F7:B3:E9:ED
[CHG] Device 00:06:F7:B3:E9:ED Trusted: yes
Changing 00:06:F7:B3:E9:ED trust succeeded
[MM100]#
- quit from bluetoothctl console
example:
play test sound using MM100 headphones¶
- Check cards availability.
example:
pactl list cards
Card #0
Name: alsa_card.platform-sound
Driver: module-alsa-card.c
Owner Module: 6
Properties:
alsa.card = "0"
alsa.card_name = "wm8731-audio"
alsa.long_card_name = "wm8731-audio"
device.bus_path = "platform-sound"
sysfs.path = "/devices/platform/sound/sound/card0"
device.string = "0"
device.description = "wm8731-audio"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card"
Profiles:
input:analog-mono: Analog Mono Input (sinks: 0, sources: 1, priority: 2, available: yes)
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-mono: Analog Mono Output (sinks: 1, sources: 0, priority: 200, available: yes)
output:analog-mono+input:analog-mono: Analog Mono Duplex (sinks: 1, sources: 1, priority: 202, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: output:analog-stereo+input:analog-stereo
Ports:
analog-input-mic: Microphone (priority: 8700, latency offset: 0 usec)
Properties:
device.icon_name = "audio-input-microphone"
Part of profile(s): input:analog-mono, input:analog-stereo, output:analog-mono+input:analog-mono, output:analog-stereo+input:analog-stereo
analog-input-linein: Line In (priority: 8100, latency offset: 0 usec)
Part of profile(s): input:analog-mono, input:analog-stereo, output:analog-mono+input:analog-mono, output:analog-stereo+input:analog-stereo
analog-output: Analog Output (priority: 9900, latency offset: 0 usec)
Part of profile(s): output:analog-mono, output:analog-mono+input:analog-mono, output:analog-stereo, output:analog-stereo+input:analog-stereo
Card #6
Name: bluez_card.00_06_F7_B3_E9_ED
Driver: module-bluez5-device.c
Owner Module: 37
Properties:
device.description = "MM100"
device.string = "00:06:F7:B3:E9:ED"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
device.form_factor = "headset"
bluez.path = "/org/bluez/hci0/dev_00_06_F7_B3_E9_ED"
bluez.class = "0x240404"
bluez.alias = "MM100"
device.icon_name = "audio-headset-bluetooth"
device.intended_roles = "phone"
Profiles:
headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)
a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: headset_head_unit
Ports:
headset-output: Headset (priority: 0, latency offset: 0 usec)
Part of profile(s): headset_head_unit, a2dp_sink
headset-input: Headset (priority: 0, latency offset: 0 usec)
Part of profile(s): headset_head_unit
We are interested in Card # 6.
- If it's not the current profile, switch to a2dp profile
example:
- play wav file from pulse subsystem to bluetooth headphones
Where:
XX_XX_XX_XX_XX_XX - MAC address from item 1 /usr/share/sounds/alsa/Front_Center.wav - is the file to be played
example:
Note: The name format of BT sink device may differ between Yocto versions. Please check the output of pactl list sinks short to get ethe exact device name.
FAQ¶
- The sound doesn't play using headphones connector (board in server mode) or BT headphones (board in client mode).
ALSA may be configured incorrectly, use this command:
Pulseaudio server may not be started, use this command:
HCI interface may be down, use this command: