Skip to content

Bluetooth A2DP

A2DP 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 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 for this to work correctly, both HCI interface and bluez-alsa server must be up & running. Please refer to the 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

  1. Connect headphones or speakers to the on-board headphones connector
  2. Put the external device into pairing mode.
  3. Make sure the external device is discoverable.
bluetoothctl
discoverable-timeout 180
discoverable on
  1. Scan and connect the external device to Variscite board.

Copy the MAC address, then approve pairing on the device if required.

bluetoothctl
power on
agent on
default-agent
pairable on
scan on
scan off
pair <mac address>
trust <mac address>
connect <mac address>
quit
  1. On the client side, connect to the device Variscite and play sound through it.

  2. Run bluealsa-aplay on device to play audio through on-board headphones or speakers:

bluealsa-aplay <mac address>

Recording from external BT source

  1. Follow the steps above to pair and connect with external BT device
  2. Check cards availability
bluealsa-aplay -L

If no cards appear, confirm you're paired with a device

  1. Record audio from the external BT source using the results from step 2:
arecord -f cd -D bluealsa:SRV=org.bluealsa,DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp test.wav

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.

bluetoothctl
discoverable-timeout 180
discoverable on

Connect

Into the console of the client device:

  1. Start utility "bluetoothctl":
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]#
  1. Prepare the connection:
power on
agent on
default-agent

example:

[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]#
  1. The first time only, to connect BT headphones, make sure they are in pairing mode. They need to show up in the scan.

  2. Enable scanning

scan on

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.

  1. Disable scanning
scan off

example:

[bluetooth]# scan off
Discovery stopped
[CHG] Controller F8:DC:7A:07:8D:A6 Discovering: no
[bluetooth]#
  1. Pair the device
pair 00:06:F7:B3:E9:ED
  1. Connect the device
connect 00:06:F7:B3:E9:ED

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]#
  1. Trust the device
trust 00:06:F7:B3:E9:ED

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]#
  1. Quit the bluetoothctl console
quit

example:

[MM100]# quit
[DEL] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
#

Play test sound using MM100 headphones

  1. Follow the steps above to pair and connect with external BT device
  2. Check cards availability
bluealsa-aplay -L
  1. Play audio to the Bluetooth speaker using the device from the previous step
aplay -D bluealsa:SRV=org.bluealsa,DEV=FC:A8:9A:EB:8F:B5,PROFILE=a2dp  /usr/share/sounds/alsa/Front_Center.wav

FAQ

  1. 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:

amixer set 'Output Mixer HiFi' on

HCI interface may be down, use this command:

hciconfig hci0 up