Thursday, September 2, 2021

Using chan_mobile with Raspberry Pi bluetooth controller

This post addresses fixing of audio issues when using chan_mobile with the built-in bluetooth controller of Raspberry Pi 4 or 3B+ (using CYW43455 chipset aka BCM43455). Audio coming in to Asterisk through the mobile sounds distorted with a tinny quality while the audio going out from Asterisk to the mobile device has no issues. The problem is due to frame size being set in chan_mobile code as 48 bytes as seen here

https://github.com/asterisk/asterisk/blob/master/addons/chan_mobile.c#L81

while bluetooth controller actually uses a frame size of 60 bytes for audio sco packets. The idea behind solution was obtained from gleaning this thread

https://github.com/raspberrypi/linux/issues/2229

Steps to resolve the issue

Stop Asterisk service and edit chan_mobile.c found in the source asterisk addons folder. The line #define DEVICE_FRAME_SIZE 48 should be changed to #define DEVICE_FRAME_SIZE 60. Then rerun 'sudo make' and 'sudo make install'. Restart Astersik service and the audio issue should be fixed.

The issue has been well described here

https://issues.asterisk.org/jira/browse/ASTERISK-29606

Hardware and Software Used: Asterisk 16.19 (Current v16), Ubuntu 20.04 on Raspberry Pi 4

It may also work with Pi 3 with the CYW43438 (BCM43438) chip but this is untested. For older firmware, if there is no audio at all Pi 3 might require running this command 

sudo hcitool cmd 0x3F 0x01C 0x01 0x02 0x00 0x01 0x01

to enable audio through HCI. Then fix given in post can be applied. You can let us know if it works for Pi 3 in comments below.