Experiencing Stuttering and Audio Interruptions in Bluetooth Calls with Pulseaudio

Hello @ferranmc,

I was able to test this on BSP 7 and the call worked without issues.

The build used the Toradex Reference Multimedia Image 7.0.0 as a base, with the following additions to local.conf:

ACCEPT_FSL_EULA = "1"

IMAGE_INSTALL:append = " pulseaudio-server pulseaudio-module-loopback pulseaudio-module-bluez5-discover pulseaudio-module-bluetooth-discover pulseaudio-module-bluetooth-policy pulseaudio-module-bluez5-device pulseaudio-module-cli pulseaudio-module-echo-cancel ofono pulseaudio pulseaudio-misc webrtc-audio-processing"

DISTRO_FEATURES:append = " pulseaudio"

After the image is built and installed to the module, you can run the following script to setup the Bluetooth communication:

#!/bin/bash

# to check if PulseAudio is running
check_pulseaudio() {
    ps aux | grep -i pulseaudio | grep -v grep > /dev/null
    return $?
}

echo "Killing and unblocking bluetooth"
rfkill unblock bluetooth
sleep 1

echo "Powering bluetooth" 
bluetoothctl power on

echo "Turn on agent"
bluetoothctl agent on 
sleep 1

echo "setting default agent"
bluetoothctl default-agent 

# Check for PulseAudio processes
process_id=$(ps aux | grep -i pulseaudio | grep -v grep | awk '{print $2}')
# If a PulseAudio process is found
if [ ! -z "$process_id" ]; then
    echo "PulseAudio process found with PID: $process_id"
    
    # Kill the PulseAudio process
    kill -9 $process_id
    
    # Verify if the process is killed
    if [ $? -eq 0 ]; then
        echo "PulseAudio process killed successfully."
    else
        echo "Failed to kill the PulseAudio process."
    fi
else
    echo "No PulseAudio process found."
fi

echo "starting Pulseaudio"
pulseaudio --start

# Wait for PulseAudio process to start
while ! check_pulseaudio; do
    echo "Waiting for PulseAudio to start..."
    sleep 1
done
echo "PulseAudio is now running."

echo "Loading sink/output device"
pactl load-module module-alsa-sink device=hw:0,0
sleep 1

echo "Setting default sink/output"
pactl set-default-sink alsa_output.hw_0_0

echo "Loading source/input"
pactl load-module module-alsa-source device=hw:0,0 

echo "Setting default source/input"
pactl set-default-source alsa_input.hw_0_0

echo "Enabling SCO "
hcitool -i hci0 cmd 0x3F 0x001D 0x00

echo "Device ready to connect/pair"

Then, using bluetoothctl:

  1. Pair to the phone
  2. Trust the phone
  3. Connect to the phone

At this point, calls from the phone should use the audio from the module as expected.

Can you give this a try and let me know how it goes for you?

Best Regards,
Bruno

Hi @bruno.tx,

I tested the image with the configuration you provided and the given script, and I successfully connected to the phone. The call works fine, but there’s noticeable echo. To fix this, I used the script mentioned in this link to enable the echo canceller. However, upon execution, I encountered the following errors:

Loading echo cancellation module  
Failure: Module initialization failed.  
Setting echo cancellation as default sink and source  
Failure: No such entity  
Failure: No such entity.  

To investigate further, I configured PulseAudio in debug mode by modifying the script and replacing pulseaudio --start with:

pulseaudio -v > pulseaudio_log.txt 2>&1 &

Additionally, I edited the daemon.conf file with the following command to enable debug logging:

vi /etc/pulse/daemon.conf

Then, I set the log level to debug:

log-level = debug

In the log file (pulseaudio_log.txt), I noticed the system is reporting the following issue:

E: [pulseaudio] module-echo-cancel.c: Master sink not found
E: [pulseaudio] module.c: Failed to load module "module-echo-cancel" (argument: "sink_name=echosink source_name=echosource aec_method=webrtc aec_args=analog_gain_control=0\ digital_gain_control=1 source_master=alsa_input.hw_0_0 sink_master=alsa_output.hw_0_0"): initialization failed.

Additionally, I directly tried the following command:

pactl load-module module-echo-cancel
25
pactl load-module module-echo-cancel aec_method=webrtc
Failure: Module initialization failed  

And I received the following error:

E: [pulseaudio] module-echo-cancel.c: Invalid echo canceller implementation 'webrtc'  
E: [pulseaudio] module.c: Failed to load module "module-echo-cancel" (argument: "aec_method=webrtc"): initialization failed.  

Do you have any suggestions or additional steps to resolve this issue?

Thanks and best regards,
Ferran

Hello @ferranmc,

The issue you see is caused by the fact that the image lacks the webrtc audio cancellation module.

I initially removed it because the build would not work with it.
Upon further investigation, it can be added to the image with the following changes:

Add the following to local.conf:

ACCEPT_FSL_EULA = "1"

IMAGE_INSTALL:append = " pulseaudio-server pulseaudio-module-loopback pulseaudio-module-bluez5-discover pulseaudio-module-bluetooth-discover pulseaudio-module-bluetooth-policy pulseaudio-module-bluez5-device pulseaudio-module-cli pulseaudio-module-echo-cancel ofono pulseaudio pulseaudio-misc"

DISTRO_FEATURES:append = " webrtc"
DISTRO_FEATURES:append = " pulseaudio"

PACKAGECONFIG:append:pn-pulseaudio = " webrtc"

Fix a dependency issue in the Pulseaudio recipe at layers/openembedded-core/meta/recipes-multimedia/pulseaudio/pulseaudio.inc:

- PACKAGECONFIG[webrtc] = "-Dwebrtc-aec=enabled,-Dwebrtc-aec=disabled,webrtc-audio-processing"
+ PACKAGECONFIG[webrtc] = "-Dwebrtc-aec=enabled,-Dwebrtc-aec=disabled,webrtc-audio-processing-1"

From here you should be able to build the image successfully and use the script from the other post to properly initialize pulseaudio with echo cancellation.

Best Regards,
Bruno

Hi Bruno,

Thank you for the instructions. I tried the changes you mentioned, and they worked perfectly. The image builds successfully now, and the Pulseaudio along with WebRTC echo cancellation is working correctly during calls.

I really appreciate your help!

Best regards,
Ferran

Hello @ferranmc,

I am glad to hear that.
Thanks for the update.

Best Regards,
Bruno