Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi Zero 2 W - Stuttering sound over Bluetooth #33

Closed
cipriantrofin opened this issue Dec 25, 2022 · 8 comments
Closed

Raspberry Pi Zero 2 W - Stuttering sound over Bluetooth #33

cipriantrofin opened this issue Dec 25, 2022 · 8 comments

Comments

@cipriantrofin
Copy link

I suspect there is an interference problem on Raspberry Pi Zero 2 W when using WiFi and Bluetooth.
I'm getting choppy / stuttering sounds when playing MP3s from my NAS and sending the output to an external Bluetooth speaker.

To replicate, I did the following:

  1. fresh Raspberry Pi OS Lite 64bit install (using the official Raspberry Pi Imager)
  2. sudo apt update && sudo apt upgrade -y + reboot
  3. add pulseaudio package - sudo apt install pulseaudio-module-bluetooth + reboot
  4. connect to external BT speaker using bluetoothctl (scan for spearker / connect to speaker)
  5. install mpg123 - sudo apt install mpg123
  6. mount a Samba share from my NAS and play an MP3 from the share, using mpg123; I get significant stutter.
@pelwell
Copy link
Member

pelwell commented Dec 29, 2022

  1. WiFi and Bluetooth operate in the same frequency bands, but it's worse for some channels than others - try changing your AP channel to see if it improves matters.

  2. Do you have experience with the older Pi Zero W and, if so, is Zero 2 W worse in this regard? The sharing mechanism between Bluetooth vs WiFi was adjusted in a CYW43438 firmware (as used on Zero W). Zero 2 W requires a different firmware, and it's possible that some similar tuning could help, but there are always going to be limitations when they share the same antenna.

@cipriantrofin
Copy link
Author

Phil, I don't have direct experience with older Pi Zero W.

With Pi Zero 2 W I had similar stuttering / choppy sound issues with a couple of firmware versions:
Firmware: BCM43430/**1** wl0: Feb 5 2021 12:49:07 version 7.45.96 (r745790) FWID 01-71817851 es7 and
Firmware: BCM43430/**1** wl0: Jul 5 2022 21:29:56 version 7.45.96.141 (g53ba0094) FWID 01-eef9b3bf es7

I came across this issue using the Moode Audio aplication (better described here: https://moodeaudio.org/forum/showthread.php?tid=4937) and - following the suggestion of Moode forum users, I decided to dwelve into it.
I know forum reports are not first hand experience, but could be still relevant:

  • NO interference when using Raspberry Pi Zero W v1.1, Pi3A and Pi3B+
  • similar interference with Pi Zero 2 W, with BCM43430/2 forum.

I had no improvement using 1, 6 and 11 WiFi channels.

@cipriantrofin
Copy link
Author

More information:

  • I booted a fresh install of Raspberry OS 64bit lite and disabled the integrated bluetooth (dtoverlay=disable-bt in /boot/config.txt)
  • after reboot, I attached an Orico BTA-508 v5.0 UBS Bluetooth dongle (RTL8761B chip) Micro USB Male to USB Female OTG Adapter / cable
  • the dongle was recognized and installed after
    sudo apt update && sudo apt upgrade -y
  • I added pulseaudio and mpg123 packages, paired / connected the speaker, mounted a share from NAS and played an mp3 file over network (using mpg123)

Result: clear sound (not 100%, but perfectly usable).

Looks like there is an interference issue with internal Bluetooth, as @pelwell suggested.

About that tuning: does this require new firmware from Cypress / Infineon or (only) Raspberry Pi OS updates ?

@pelwell
Copy link
Member

pelwell commented Jan 10, 2023

The relevant changes are actually to the "nvram" files - text files containing various settings - which means it should be easy to test a fix.

Note that in my limited testing now I've not seen a problem with stuttering, but the WiFi performance was suspiciously lousy so it isn't really a fair test. This means that I have no real confidence that these changes will improve things, but it's a simple change and easy to revert so worth a try.

I'm assuming from your comment above that your Zero 2 W is the 43430/1 variant, but the change is the same for both, just to different files:

  • If dmesg | grep brcmfmac contains using brcm/brcmfmac43436s-sdio for chip BCM43430/1, edit /lib/firmware/brcm/brcmfmac43436s-sdio.raspberrypi,model-zero-2-w.txt.
  • If dmesg | grep brcmfmac contains using brcm/brcmfmac43436-sdio for chip BCM43430/2, edit /lib/firmware/brcm/brcmfmac43436-sdio.raspberrypi,model-zero-2-w.txt.

The proposed change, which I think will be the same for both devices, is to append the following lines:

# Improved Bluetooth coexistence parameters
btc_mode=1
btc_params8=0x4e20
btc_params1=0x7530

Obviously, reversion is simply a matter of deleting them.

Give it a try and let me know how you get on.

@pelwell
Copy link
Member

pelwell commented Jan 10, 2023

Update: with a different test setup I do see stuttering without the change and an improvement with it, but the improvement comes at the cost of a large reduction in throughput while there is Bluetooth traffic - unfortunately that is always going to be the case.

@cipriantrofin
Copy link
Author

Thank you, @pelwell. I followed your instructions and it looks solved.

I don't know how to check the reduction in WiFi throughput, but - in my use case - there is enough left to stream Internet Radio or mp3s from local network,

pelwell added a commit that referenced this issue Jan 11, 2023
The addition of some Bluetooth coexistence parameters allows better
sharing of bandwidth between Bluetooth and WiFi.

See: #33
@pelwell
Copy link
Member

pelwell commented Jan 11, 2023

Thanks for the feedback. These coexistence parameters will be present in future releases.

@sudo-splinter-cell
Copy link

sudo-splinter-cell commented Mar 24, 2024

Are we absolutely certain that these lines are necessary accross the board with all Pi devices out there? I was searching for a way to fix my bluetooth audio issues on my Raspberry Pi-5 since the day i purchased it. Same kind of issues were also present with my Pi-4 (but less frequent). Pulsaudio or pipewire, all the same. Disabled wifi, still had issues. I then came up with the forum post that directed me to here. I checked my "relevant" file (for RPI-5 it is brcmfmac43455-sdio.txt). I found that the lines mentioned in this bug report (and one more line) was added to this file also, even though it is a different kind of chip on a different kind of Pi. The lines were:

#btc_mode=1
#btc_params8=0x4e20
#btc_params1=0x7530
#btc_params50=0x972c

As you can see, i have commented them out, just to see if it will change things for the better for me. It is too early to say but i am having very fewer and far in between bluetooth audio stutters or hiccups since i have commented them out. I will continue testing for a week and share my results.

PS: I am on a 5ghz wifi connection. Haven't tried 2.4 ghz. But i assume these lines were added to make it possible for 2.4ghz wifi and bluetooth to coexist. But maybe, to make it happen, they somewhat "hamper" the bluetooth audio connections (or even slow down wifi in the process). I think this deserves some investigation.

PS-2: My wifi connection speed might have also increased after commenting out those lines. I need more testing time to make sure though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants