Bluetooth audio sources and sinks

Bluetooth is unfortunately a technology that, despite being ubiquitous, suffers from its proprietary nature. As a result, support for the full range of Bluetooth functionality (in the form of profiles) is lacking. The profile that we are interested in for this project is called Advanced Audio Distribution Profile (A2DP). This is the profile used by everything from Bluetooth headphones to Bluetooth speakers in order to stream audio.

Any device that implements A2DP can stream audio to an A2DP receiver or can themselves act as a receiver (depending on the BT stack implementation). Theoretically, this would allow someone to connect with a smartphone or similar device to our infotainment system and play back music on it, as they would with a standalone Bluetooth speaker.

A receiver in the A2DP profile is an A2DP sink, whereas the other side is the A2DP source. A Bluetooth headphone or speaker device would always be a sink device as they can only consume an audio stream. A PC, SBC, or similar multi-purpose device can be configured to act as either a sink or a source.

As mentioned earlier, the complications surrounding the implementation of a full Bluetooth stack on mainstream OSes has led to lackluster support for anything more than the basic serial communication functionality of Bluetooth.

While FreeBSD, macOS, Windows, and Android all have Bluetooth stacks, they are limited in the number of Bluetooth adapters they can support (just one on Windows, and only USB adapters), the profiles they support (FreeBSD is data-transfer-only), and configurability (Android is essentially only targeted at smartphones).

For Windows 10, A2DP profile support has currently regressed from being functional in Windows 7 to not being functional as of the time of writing due to changes to its Bluetooth stack. With macOS, its Bluetooth stack added A2DP support with version 10.5 of the OS (Leopard, in 2007) and should function.

The BlueZ Bluetooth stack that has become the official Bluetooth stack for Linux was originally developed by Qualcomm and is now included with official Linux kernel distributions. It's one of the most full-featured Bluetooth stacks.

With the move from BlueZ version 4 to 5, ALSA sound API support was dropped, and instead moved to the PulseAudio audio system, along with the renaming of the old APIs. This means that applications and code implemented using the old (version 4) API no longer work. Unfortunately a lot of the example code and tutorials one finds online still targets the version 4, which is something to be aware of, as they work very differently.

BlueZ is configured via the D-Bus Linux system IPC (interprocess communication) system, or by editing configuration files directly. Actually implementing BlueZ support in an application like that in this chapter's project to configure it programmatically would be fairly complicated however, due to the sheer scope of the APIs, as well the limitations in setting configuration options that go beyond just the Bluetooth stack and require access to text-based configuration files. The application would therefore have to run with the correct permissions to access certain properties and files, editing the latter directly or performing those steps manually.

Another complication for the infotainment project is setting up an automatic pairing mode, as otherwise the remote device (smartphone) would be unable to actually connect to the infotainment system. This would require constant interaction with the Bluetooth stack as well, to poll it for any new devices that may have connected in the meantime.

Each new device would have to be checked to see whether it supports the A2DP source mode, in which case it would be added to the audio input for the system. One could then hook into the audio system to make use of that new input.

Due to the complexity and scope of this implementation, it was left out of the example code in this chapter. It could, however, be added to the code. SBCs such as the Raspberry Pi 3 come with a built-in Bluetooth adapter. Others can have a Bluetooth adapter added using a USB device.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.147.77