Broadcast Audio URI
Tags: leaudio, web, bluetooth, zephyr
Published: 2024-06-06 20:56:37

---
title: Broadcast Audio URI
published: true
description:
tags: LEAudio, Web, Bluetooth, Zephyr
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjp0zzgrwwfyrrdmc2ey.png
# published_at: 2024-06-06 22:30 +0000
---

# Audio sharing is caring
Until recently, most generic Bluetooth enabled speakers and headsets have been using Bluetooth Classic. With the introduction of [Bluetooth LE Audio](https://www.bluetooth.com/learn-about-bluetooth/feature-enhancements/le-audio/), a wide new range of solutions become possible and one of the most exciting ones is the possibility to broadcast audio, where the sender and receiver are no longer required to be connected (like the 1-1 Bluetooth Classic case - e.g a phone and a headset).

> _"LE Audio introduces broadcast audio to Bluetooth® technology, a new feature that enables an audio transmitter to broadcast to an unlimited number of nearby Bluetooth audio receivers. Broadcast audio opens significant new opportunities for innovation, including a powerful new capability, Auracast™ broadcast audio._
>
> _Auracast™ broadcast audio is a set of defined configurations of Bluetooth® broadcast audio which are specified within the Public Broadcast Profile (PBP) specification that enables new, globally interoperable audio experiences for consumers."_

Read more about Auracast here: https://www.bluetooth.com/auracast/developers/


# Sharing Links to Broadcasts
Even though it is possible to scan for nearby broadcasts using a [Broadcast Audio Assistant](https://www.bluetooth.com/auracast/how-it-works/), sometimes, it will be more practical for users to 'tune in' to Broadcast sources using a trusted link provided through other means.

The [Broadcast Audio URI](https://www.bluetooth.com/specifications/specs/broadcast-audio-uri-2/) is an exciting new spec that allows just that: Information about a Broadcast Audio Source to be conveyed over an out-of-band (OOB) medium to a Broadcast Audio Assistant - or, if the Broadcast Sink supports it, directly by e.g. touching an NFC tag, containing the Broadcast Audio URI, with a speaker or earbuds.

An example from the spec: 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aodcm2qe8edu74vcm819.png)

This includes all the information for a Broadcast Sink to find the right broadcast.  The data in the QR code is this text:

```
BLUETOOTH:UUID:184F;BN:SG9ja2V5;SQ:1;AT:0;AD:AABBCC001122;AS:1;BI:DE51E9;PI:F
FFF;NS:1;BS:1;;
```

Which roughly translates to:

"Related to the 0x184F UUID (Broadcast Audio Scan Service), there is a Standard Quality mono channel broadcast at addresss AA:BB:CC:00:11:22 with Broadcast ID 0x0E51E9 and the Broadcast name 'Hockey'"

# Zephyr for the win!
The [Zephyr RTOS](https://www.zephyrproject.org/) is a very powerful OS for embedded devices and it also includes support for [LE Audio](https://docs.zephyrproject.org/latest/connectivity/bluetooth/api/audio/bluetooth-le-audio-arch.html).  If this is the first time you hear about it, please check some of my other posts on getting started with Zephyr, e.g. [Getting started with Zephyr and Web Bluetooth](https://dev.to/denladeside/getting-started-with-zephyr-and-web-bluetooth-355d)

In the Zephyr repo, there is a [Broadcast Audio Source sample](https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/bap_broadcast_source) that was used as a starting point.

There is also great support for different displays, which we will need to display the Broadcast Audio URI in a QR code.

To my happy surprise, there was already [QR code support](https://docs.lvgl.io/master/libs/qrcode.html) in the [LVGL](https://lvgl.io/) module included in Zephyr so I implemented some minimal QR-Code functionality to expose the required data once the Broadcast source was ready on the device. As this is a PoC, the non-changing parameters are hardcoded:

```c
void gui_update_qr_code(const bt_addr_t *addr, uint32_t broadcast_id, uint8_t *name)
{
	uint8_t addr_str[13];
	uint8_t name_base64[128];
	size_t name_base64_len;

	/* Address */
	snprintk(addr_str, sizeof(addr_str), "%02X%02X%02X%02X%02X%02X",
			addr->val[5], addr->val[4], addr->val[3],
			addr->val[2], addr->val[1], addr->val[0]);

	/* Name */
	base64_encode(name_base64, sizeof(name_base64), &name_base64_len, name, strlen(name));
	name_base64[name_base64_len + 1] = 0;

	/* Most fields hard coded for this demo */
	snprintk(qr_data, sizeof(qr_data),
		 "BLUETOOTH:UUID:184F;BN:%s;SQ:1;AT:1;AD:%s;AS:0;BI:%06X;PI:FFFF;NS:1;BS:1;;",
		 name_base64, addr_str, broadcast_id);

	lv_qrcode_update(qr_code, qr_data, strlen(qr_data));
	lv_task_handler();
}
```

The result is here:

![Broadcast Audio URI QR code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjr0o7ikrewb1iraujsc.jpg)

# Try it out!
Put together, here is a PoC of how a [Broadcast Audio URI](https://www.bluetooth.com/specifications/specs/broadcast-audio-uri-2/) can be used to expose a dynamically generated QR code on an nRF5340 Audio DK with a screen attached.

> Hardware used:
>  * [nRF5340 Audio DK](https://www.nordicsemi.com/Products/Development-hardware/nRF5340-Audio-DK)
>  * [Adafruit 2.8" TFT Touch Shield](https://www.adafruit.com/product/1947)
>

The code is available here: https://github.com/larsgk/bau-source

Connecting the board to the USB port of any host device supporting USB Audio (Windows, Linux, Mac, Android, ChromeOS, etc), will automatically make the connected board a Broadcast Audio Source, streaming whatever is played on the host device. If you have access to one of the latest Samsung mobile phones and Galaxy Buds2 Pro, you should be able to find and select the broadcast and hear it in the earbuds.

# See it in action
Currently, there are no implementations of the full Broadcast Audio URI flow in any device available on the market, so I have been using a dedicated web based stand-alone broadcast assistant application, modified to read and parse the Broadcast Audio URI QR code (this will be covered in a future post).  It's using the [BarcodeDetector API](https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector) on supported devices to read the QR code.

It allows a user to scan a Broadcast Audio URI QR code and add it directly to an attached Broadcast Sink (e.g earbuds able to receive broadcasts, like the Samsung Galaxy Buds2 Pro).

The result is here:

{% youtube NZ0PG1rOZYQ %}

Credits to [Nick Hunn](https://www.nickhunn.com/), [Hai Shalom](https://www.linkedin.com/in/haishalom/) and others on doing great work on the [Broadcast Audio URI ](https://www.bluetooth.com/specifications/specs/broadcast-audio-uri-2/)