Suicide-Squirrel / issues_oreo

Issue tracker for Oreo (aoscp, LOS, RR...)
5 stars 0 forks source link

Bluetooth voice / call distorted #1

Closed steadfasterX closed 5 years ago

steadfasterX commented 6 years ago

Using a BT headset for calling has an extreme background noise / robotic sound . Audio over Bluetooth works fine

One plus 2 logs:

https://bpaste.net/show/e31575776594 https://bpaste.net/show/2acee30e9807

ThePiGuy0 commented 6 years ago

I've repasted these into bpaste again and have a local copy as I noticed they expire in 20 mins

https://bpaste.net/show/1df07535244f https://bpaste.net/show/2a8de5cd097c

steadfasterX commented 6 years ago

Perfect thx! :)

(I have updated the first post with new ones with an expiry of never )

Bobklusky commented 5 years ago

Wasn't sure how to "vote" for this another way but I just wanted to let you know that this is the bug that pains me the most. I never leave the house without my BT headset on and really loved using it for hands-free calls on my d802 and h815 prior to flashing AOSCP. Do we have any sort of a lead on what might be causing that background noise during the calls? Is it some default BT audio quality profile that kicks in here, something forcing the connection to drop the quality to the minimum? Some codec missing?

ThePiGuy0 commented 5 years ago

I've explained the problem in greater detail here

https://forum.xda-developers.com/showpost.php?p=78111758&postcount=1009

asafsarid commented 5 years ago

Is there any workaround for this issue? Any progress maybe?

steadfasterX commented 5 years ago

https://forum.xda-developers.com/g4/development/lineageos-15-1-lg-g4-t3782722/post78716790

Bullnados commented 5 years ago

Can you detail the heading? For me Bluetooth Audio is working, only calls via Bluetooth have the robotic sound problems

steadfasterX commented 5 years ago

Can you detail the heading? For me Bluetooth Audio is working, only calls via Bluetooth have the robotic sound problems

Done

steadfasterX commented 5 years ago

for reference (while nothing in there was able to solve the issue yet):

https://forum.xda-developers.com/showpost.php?p=78902533&postcount=5262

Tested without any diff: https://review.lineageos.org/c/LineageOS/android_hardware_samsung/+/182054

The ref guide for our chip: CYW4339_aka_BCM4339_Single_Chip_5G_WiFi_IEEE_802.11ac.pdf

Based on that spec sheet I identified the (hopefully) related android flags. The following is an example of what I think should match the spec sheet (but doesn't work ofc):

########################################################################
# 0:8K     1:16K     2:4K     default:1
SCO_WBS_SAMPLE_RATE = 1
########################################################################
# 0:disable     1:enable    default:1
SCO_I2SPCM_IF_MODE = 1
########################################################################
# 0:slave       1:master        default:1
SCO_I2SPCM_IF_ROLE = 0
########################################################################
# 0:8K     1:16K     2:4K     default:0
SCO_I2SPCM_IF_SAMPLE_RATE = 1
########################################################################
# 0:128K     1:256K     2:512K     3:1024K     4:2048K    default:1
SCO_I2SPCM_IF_CLOCK_RATE = 3
########################################################################
# 0:128K     1:256K     2:512K     3:1024K     4:2048K    default:2
SCO_I2SPCM_IF_CLOCK_RATE4WBS = 1
########################################################################
# 0:PCM  1:Transport  2:Codec  3:I2S  default:0
SCO_PCM_ROUTING = 0
########################################################################
# default: FALSE
SCO_USE_I2S_INTERFACE = FALSE
########################################################################
# 0: slave, 1: master, default: 0, usually == SCO_I2SPCM_IF_ROLE
SCO_PCM_IF_CLOCK_MODE = 0
########################################################################
# 0: slave, 1: master, default: 0, usually == SCO_PCM_IF_CLOCK_MODE
SCO_PCM_IF_SYNC_MODE = 0
########################################################################
# should be consistent with SCO_I2SPCM_IF_CLOCK_RATE
# 0:128K     1:256K     2:512K     3:1024K     4:2048K    default:4
SCO_PCM_IF_CLOCK_RATE = 3
########################################################################
pilophae commented 5 years ago

I think that SCO_WBS_SAMPLE_RATE should be 2. See section 7.3.4 in the linked PDF.

pilophae commented 5 years ago

This is weird too: "The default format is 13-bit 2’s complement data, left justified, and clocked MSB first."

Where can I find more of these flags?

steadfasterX commented 5 years ago

I think that SCO_WBS_SAMPLE_RATE should be 2. See section 7.3.4 in the linked PDF.

exact that sections states 16khz in SBC mode which is the default. Regardless I played with all of the above settings and changed all of them and dozens of combinations between clock rates, sync modes and sample rates.. no success.

if you route through I2S instead of PCM with: SCO_USE_I2S_INTERFACE it changes the direction of that issue though:

Set SCO_USE_I2S_INTERFACE = FALSE (so the default) and the incoming voice is distorted while outgoing is fine. change it to SCO_USE_I2S_INTERFACE = TRUE and the incoming voice is ok but outgoing is distorted.

Ofc I changed the I2S settings like clock rate etc accordingly but well no idea if doing it correctly. Also I guess that means changing mixer_paths.xml as well so it routes through I2S but again no idea.

Where can I find more of these flags?

many if not all are defined here: hardware/broadcom/libbt/include/bt_vendor_brcm.h click

pilophae commented 5 years ago

Have you tried disabling WBS?

steadfasterX commented 5 years ago

Have you tried disabling WBS?

sure

pilophae commented 5 years ago

Seems as if eSCO support was added in Oreo. This seems like it could have something to do with this issue: https://android.googlesource.com/platform/system/bt/+/57f6508cf7b22788fa2e7a739cec241b785718fb

I will read some code and try to discern the differences in the SCO flags during setup between Nougat and Oreo.

steadfasterX commented 5 years ago

Seems as if eSCO support was added in Oreo. This seems like it could have something to do with this issue: https://android.googlesource.com/platform/system/bt/+/57f6508cf7b22788fa2e7a739cec241b785718fb

I will read some code and try to discern the differences in the SCO flags during setup between Nougat and Oreo.

nice finding.. especially

Number of Broadcom vendor specific commands(VSCs)that are needed to be sent to Broadcom controllers along with this command have also been updated accordingly

NOTE: This change would also need a firmware patch for the feature to work on Broadcom contollers which will be delivered to Google in a separate change set.

pilophae commented 5 years ago

Tried to send an email to the author of the above commit. Fail.

I found some firmware variants: 2016-11-30: https//github.com/vinothraj-aricent/platform-external-imx-firmware/tree/d216b6075286ac7efaf87ca54fc0985ebd1832dc/brcm/ZP_BCM4339 2016-02-17: https://android.googlesource.com/platform/hardware/broadcom/wlan/+/master/bcmdhd/firmware/bcm4339/

pilophae commented 5 years ago

Ah, nevermind, those are for the WiFi. I guess the .hcd files are for Bluetooth.

steadfasterX commented 5 years ago

Wouldn't help at all as we would need files patched for the above commit so later ones. Anyways I will try to revert those esco commits and see if that is possible..

sashko9807 commented 5 years ago

The last time I was digging into this, the issue seemed more related to the removal of VSCs for SCO configuration. Tried to explain most of it here: https://forum.xda-developers.com/showpost.php?p=79239414&postcount=3

I tried to replicate the send_command method to in vendor.cc https://github.com/Unlegacy-Android/android_system_bt/blob/b2a292b5d8df2f359c38b0787bc01181225a9bc9/hci/src/vendor.cc#L133](url), and partially revert eSCO commit 3/5: https://github.com/Unlegacy-Android/android_system_bt/commit/a9152a2892750ccb30df1907cb82480bd26dec43 in order to retrieve the older SCO configuration which was made via libbt-vendor thanks to an opcode call in set_audio_state method: https://github.com/Unlegacy-Android/android_system_bt/blob/aosp-7.1/hci/src/hci_audio.c

The issue I had was that neither Hci_Enhanced_Setup_Synchronous_Connection or Setup_Synchronous_Connection command were send, thus the SCO/eSCO connection was never established.

What I thought to be the culprit of this issue: https://github.com/Unlegacy-Android/android_system_bt/commit/a9152a2892750ccb30df1907cb82480bd26dec43#diff-91f58eb08ce9dea17af6a8fd5d3b313aL452 By app I think the owner of the commit meant the Bluetooth app, but still I had no idea how to make this call, maybe you will.

steadfasterX commented 5 years ago

@sashko9807 you are so far ahead of me .. If you cannot solve it how do I? You understand more of that C/C++ crap then me so the only thing I do is read, try, fail, read, try, fail.

sashko9807 commented 5 years ago

Unfortunetaly I no longer have a device to make tests. Maybe we can try something easier using common sense. You mention that when you set SCO_USE_I2S_INTERFACE tag as true the output is fine, so lets focus on that. Looking at the code inside hw_sco_config method https://android.googlesource.com/platform/hardware/broadcom/libbt/+/refs/tags/android-9.0.0_r34/src/hardware.c#1254

When SCO_USE_I2S_INTERFACE =TRUE the sco_bus_clock_rate is set to the value of SCO_I2SPCM_IF_CLOCK_RATE which by default is set 256k https://android.googlesource.com/platform/hardware/broadcom/libbt/+/refs/tags/android-9.0.0_r34/include/bt_vendor_brcm.h#283

When SCO_USE_I2S_INTERFACE =FALSE the sco_bus_clock_rate is set to the value of SCO_PCM_IF_CLOCK_RATE which by default is set 2048k https://android.googlesource.com/platform/hardware/broadcom/libbt/+/refs/tags/android-9.0.0_r34/include/bt_vendor_brcm.h#321

Set SCO_PCM_IF_CLOCK_RATE value to 256k and SCO_USE_I2S_INTERFACE =FALSE, and check how is the input/output.

This commit would also be needed if it hasn't been merged to your local project already: https://review.lineageos.org/c/LineageOS/android_hardware_interfaces/+/233817/3/bluetooth/1.0/default/vendor_interface.cc

Hope this works.

Edit: Shame on me that I couldn't realize it earlier, but perhaps we could avoid the hw_set_audio_state() call. Check line 1303, by simply adding an else condition for the PCM routing we could possibly continue the configuration for SCO. Its a bit hacky, but it could possibly do the job. Will be something like

if (SCO_INTERFACE_I2S == sco_bus_interface) {   hw_sco_i2spcm_config(SCO_CODEC_CVSD);   } else if(SCO_INTERFACE_PCM == sco_bus_interface) {   hw_sco_i2spcm_config(SCO_CODEC_CVSD); }

At least to me this one sounds way more hopeful than the above suggestion with the clock rate

steadfasterX commented 5 years ago

Set SCO_PCM_IF_CLOCK_RATE value to 256k and SCO_USE_I2S_INTERFACE =FALSE, and check how is the input/output.

I already tried every clock rate here already.. :(

This commit would also be needed if it hasn't been merged to your local project already: https://review.lineageos.org/c/LineageOS/android_hardware_interfaces/+/233817/3/bluetooth/1.0/default/vendor_interface.cc

ok haven't that one. will add and test it when back next week

Edit: Shame on me that I couldn't realize it earlier, but perhaps we could avoid the hw_set_audio_state() call. Check line 1303, by simply adding an else condition for the PCM routing we could possibly continue the configuration for SCO. Its a bit hacky, but it could possibly do the job. Will be something like

if (SCO_INTERFACE_I2S == sco_bus_interface) {   hw_sco_i2spcm_config(SCO_CODEC_CVSD);   } else if(SCO_INTERFACE_PCM == sco_bus_interface) {   hw_sco_i2spcm_config(SCO_CODEC_CVSD); }

At least to me this one sounds way more hopeful than the above suggestion with the clock rate

thx I'm happy for any suggestion. So I would set these and let SCO_USE_I2S_INTERFACE=FALSE right?

sashko9807 commented 5 years ago

Yes.

sashko9807 commented 5 years ago

Doesn't work

steadfasterX commented 5 years ago

@sashko9807 you mean you tested the above already?

sashko9807 commented 5 years ago

@sashko9807 you mean you tested the above already?

Yes.

Set SCO_USE_I2S_INTERFACE = FALSE (so the default) and the incoming voice is distorted while outgoing is fine. change it to SCO_USE_I2S_INTERFACE = TRUE and the incoming voice is ok but outgoing is distorted.

Try this commit if you want to route through I2S. As per BCM4339 documentation the input clock mode needs to be configured as a slave.

Entretoize commented 5 years ago

I had the same issue on Lineage 15, I installed AOSCP (android 9) and have the same issue again...

steadfasterX commented 5 years ago

I had the same issue on Lineage 15, I installed AOSCP (android 9) and have the same issue again...

that's nothing new .. the issue is well known since oreo and ofc it is also in pie: https://github.com/Suicide-Squirrel/issues_pie/issues/5

Entretoize commented 5 years ago

Ok, sorry to ask here but is there a trick to temporary correct that ?

steadfasterX commented 5 years ago

If there were any it would be mentioned here. So no.

steadfasterX commented 5 years ago

wow.. finally .. we HAVE A FIX FOR THAT SHIT!!! I will do some tests now and update this asap but IT WORKS :) ffs..

steadfasterX commented 5 years ago

All credits going to: z3DD3r (XDA nick) aka @zeDDer (github) and Sashko98 (XDA nick) aka @sashko9807 (github)!

They did a great job and so finally were able to fix it for that Broadcom chip (affects Nexus 5, LG G4 and maybe others like nextbit, oneplus2 , .. )

https://forum.xda-developers.com/showpost.php?p=79747463&postcount=5 https://forum.xda-developers.com/showpost.php?p=79751310&postcount=11 https://forum.xda-developers.com/showpost.php?p=79753114&postcount=16

the origin patch: https://github.com/zeDDer/android_hardware_broadcom_libbt/commit/ab123278df9975e870143c7604b2ec74a8929873

implemented for my builds with:

I may implement an auto-sync for that repo with LOS upstream and auto-rebase that patch on every new change that might come in the future (not that likely but if..)

Current known issue:

Entretoize commented 5 years ago

Thank you for the update, but what to do with that ? Do we need to build and reinstall the rom ? This seems to be a library, maybe we can just overwrite the original in system...

steadfasterX commented 5 years ago

Thank you for the update, but what to do with that ? Do we need to build and reinstall the rom ? This seems to be a library, maybe we can just overwrite the original in system...

either wait until my builds are ready or build by yourself. this is nothing you can do by just replacing a file its a change deep in the android sources.

Entretoize commented 5 years ago

Understood... sorry I'm in an unknown world here, I can wait (I'm not sure to be able to build myself) but are you releasing builds often, how much days (weeks...) are we talking about ?

steadfasterX commented 5 years ago

Understood... sorry I'm in an unknown world here, I can wait (I'm not sure to be able to build myself) but are you releasing builds often, how much days (weeks...) are we talking about ?

I build whenever it is necessary and that fix has the highest priority ever. Expect a build "soon" so in the next hours or until Friday evening latest (depending if building fails for any reason for other models)

sashko9807 commented 5 years ago

Thank you for the update, but what to do with that ? Do we need to build and reinstall the rom ? This seems to be a library, maybe we can just overwrite the original in system...

either wait until my builds are ready or build by yourself. this is nothing you can do by just replacing a file its a change deep in the android sources.

The change is just in libbt-vendor, replacing it should apply the hack into any G4 rom.

steadfasterX commented 5 years ago

Uh yea sure but you still need to build.. There is no way around .