yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] ego42:
Hi,

I just want to say that since unfortunately my programming capabilities are close to non-existent I'm afraid I'm not able to provide much actual help in solving this issue but i highly appreciate that there are people who are looking into this and trying to remedy what Android OS designers and phone manufacturers neglected. I've been using A2DP headsets for the past 3-4 years with Nokia E51 and E52 phones which provided very good sound quality virtually indistinguishable from a cable connection and now after buying a Samsung Galaxy S phone I'm terribly disappointed at its A2DP performance comparable to 112kbps MP3s with even the highest quality sources.

I own three different A2DP headsets manufactured by Sony Ericsson, Nokia and unnamed Chinese labourers respectively and a set of quality IEM earphones plugged into quite good and relatively trained ears. Since A2DP support on both Nokias and a Samsung Blackjack I owned shortly (and let go of just because of its pitiful A2DP performance) has not always been perfect I know a thing or two about how A2DP works and performs. So if there is anything I can do to help regarding testing, preparing and submitting logs etc. just let me know and I will be very happy to help if that's what is needed.

Thanks!

Petr
[Android Software/Hacking General [Developers Only]] bex0rs:
If I'm wrong about headsets reporting their desired bitpool values, and in fact they aren't providing that information at all, then a quick modification of sbc.c can be done to change the default sbc encoder settings:

static void sbc_set_defaults(sbc_t *sbc, unsigned long flags)
{
sbc->frequency = SBC_FREQ_44100;
sbc->mode = SBC_MODE_STEREO;
sbc->subbands = SBC_SB_8;
sbc->blocks = SBC_BLK_16;
[B]sbc->bitpool = 32;[/B]
#if __BYTE_ORDER == __LITTLE_ENDIAN
sbc->endian = SBC_LE;
#elif __BYTE_ORDER == __BIG_ENDIAN
sbc->endian = SBC_BE;
#else
#error "Unknown byte order"
#endif
}

You may even be able to do a hex edit on the libsbc binary to set the default to 53 by changing a few bytes in the right place.

The information in my previous post is still good, but I think this post is a better starting point for someone out there who's willing to give this a shot and report back.
[Android Software/Hacking General [Developers Only]] mcheffe:
I tried making the change suggested above in sbc.c to set the default bitpool to 54 but logcat still shows the same 32:2 value when I turn on my headphones.

W/BTLD ( 432): ### alloc : 3, blk len 240, chmode:15, bitpool 32:2, subbands 12

To test the change I recompiled the whole Android build and dropped a new liba2dp.so on my HD2. Maybe that's not the .so that contains this code or maybe there's something else. I'll experiment more and see what I can figure out.
[Android Software/Hacking General [Developers Only]] bex0rs:
If you're making the change in post #21, then I think you'll want to replace the libsbc binary. If you've already done that and you are still getting a negotiated bitpool of 32, then that means your headset might be reporting a max bitpool of 32 (thus overriding whatever you set in sbc.c) so you should look at post #19 for some possible edits to liba2dp.
[Android Software/Hacking General [Developers Only]] mcheffe:
Yes, based on the build output, it looks like sbc.c is linked into liba2dp.so.
[Android Software/Hacking General [Developers Only]] mcheffe:
While changing liba2dp.so didn't seem to affect anything, also changing libaudio.so breaks the bluetooth device connection.

I/BluetoothA2dpService( 224): checkSinkSuspendState() : state = 2 prevState = 0

I/BluetoothA2dpService( 224): checkSinkSuspendState() : mTargetA2dpState = -1

I/BluetoothA2dpService( 224): checkSinkSuspendState() : initialStart = false initialSuspend = false

I/BluetoothA2dpService( 224): setSinkPriority = Auto Connect

D/BluetoothA2dpService( 224): A2DP state : device: 00:0F:F6:2C:06:15 State:0->2

E/BTLD ( 416): bta_av_link_role_ok hndl:x41 role:1, conn_audio:x1, bits:1, features:x1

W/BTLD ( 416): bta_dm_rm_cback:1, status:0

W/BTLD ( 416): new conn_srvc id:18, app_id:0

E/BTLD ( 416): Disabling LPM

E/BTLD ( 416): bta_av_start_ok suspending: 0, role:x0

I/BTL-IFS ( 416): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 44 pbytes (hdl 15)

E/BTL_AV_CODEC: ( 416): Not started yet!

E/BTL_AV_CODEC: ( 416): Not started yet!

E/BluetoothEventLoop.cpp( 224): event_filter: Received signal org.bluez.AudioSink:Playing from /org/bluez/433/hci0/dev_00_0F_F6_2C_06_15

E/BluetoothEventLoop.cpp( 224): event_filter: Received signal org.bluez.AudioSink:PropertyChanged from /org/bluez/433/hci0/dev_00_0F_F6_2C_06_15

E/BluetoothEventLoop.cpp( 224): event_filter: Received signal org.bluez.AudioSink:PropertyChanged from /org/bluez/433/hci0/dev_00_0F_F6_2C_06_15

I/BluetoothA2dpService( 224): checkSinkSuspendState() : state = 4 prevState = 2

I/BluetoothA2dpService( 224): checkSinkSuspendState() : mTargetA2dpState = -1

I/BluetoothA2dpService( 224): checkSinkSuspendState() : initialStart = false initialSuspend = false

D/A2DP ( 184): a2dp_init rate: 44100 channels: 2

D/A2DP ( 184): a2dp_thread started

D/A2dpAudioInterface( 184): A2dpAudioStreamOut::set 80, 0, 0, 0

D/A2dpAudioInterface( 184): setBluetoothEnabled 1

I/BluetoothA2dpService( 224): Send mute tone for remote AVDTP START

D/A2DP ( 184): bluetooth_init

E/A2DP ( 184): bt_audio_service_open failed

I/AudioFlinger( 184): AudioFlinger's thread 0x1ebf0 ready to run

I'm wondering if these files need to be built along with the ROM they're running on so that they maintain compatibility with other libraries in the system.

It looks to me like the source is broken down like this (based on the Android.mk Makefile in bluez/audio):

libaudio.so:

a2dp.c

avdtp.c

control.c

device.c

gateway.c

headset.c

ipc.c

main.c

manager.c

module-bluetooth-sink.c

sink.c

source.c

telephony-dummy.c

unix.c

liba2dp.so:

liba2dp.c

ipc.c

../sbc/sbc.c.arm

../sbc/sbc_primitives.c

../sbc/sbc_primitives_neon.c

Note that liba2dp.so refers to sbc.c.arm and not sbc.c. I don't know if sbc.c.arm is generated from sbc.c or what. I don't understand much of this yet as I'm still trying to learn the Android build.

Also, comments in the Makefile imply that libaudio.so is the A2DP plugin and liba2dp.so is used by Audioflinger. It is also possible to interpret the comments as meaning both the .so's comprise the plugin and liba2dp.so part is linked in to Audioflinger.

Anyway, not much progress yet...
[Android Software/Hacking General [Developers Only]] jonboyuk:
Keep at it, I'd love it if you could fix this!! My HD2 will then be the perfect device!
[Android Software/Hacking General [Developers Only]] mcheffe:
I do plan to try more experiments on this, just been busy lately. I've been running my modified liba2dp.so on my HD2 for a while now but I don't think it's having much effect. I really need to figure out what files comprise all the pieces of the Bluez implementation so I can test a proper install of all the files I built.

Sent from my HTC HD2
[Android Software/Hacking General [Developers Only]] mcseven:
Hi all, having the same trouble with low quality a2db, even if it's way better than stupid WP7. There are some config files in "/etc/bluetooth/" on my Desire HD running Froyo, might this be a way to change A2DP settings? I'm in no way familiar with linux or conf files, but I'd hesitate to use other than stock roms or do some recompiling myself. Thanks, Cheers...
[Android Software/Hacking General [Developers Only]] CzarDestructo:
Looks like Cyanogen sets the bitpool based on sampling frequency, which makes sense. For high sample rates they use 31, for low samples they use 53.

Code repository for Cyanogen Froyo is here

static uint8_t a2dp_default_bitpool(uint8_t freq, uint8_t mode)
{
switch (freq) {
case BT_SBC_SAMPLING_FREQ_16000:
case BT_SBC_SAMPLING_FREQ_32000:
return 53;

case BT_SBC_SAMPLING_FREQ_44100:

switch (mode) {
case BT_A2DP_CHANNEL_MODE_MONO:
case BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL:
return 31;

case BT_A2DP_CHANNEL_MODE_STEREO:
case BT_A2DP_CHANNEL_MODE_JOINT_STEREO:
return 53;

default:
DBG("Invalid channel mode %u", mode);
return 53;
}
[Android Software/Hacking General [Developers Only]] geatsch:
Well I´m also interested on a solution regarding this problem.

Just updated latest HTC Stock 2.29.405.2 and compared to previous Version it looks like something has changed (louder/quality?) - log still shows bitpool of 32

Config:

HW: HTC Desire

Player: Poweramp + equalizer

Headset: Sennheiser MM450

Anyone experiencing changes regarding A2dp for this rom version?

Beside this i wont use cyanogen mod - so i would appreciate a solution which works for nearly everyone

You can change bitpool on other mobile os very easy but not on android - ridiculous

I contribute some testing if some generic solution could be possible - i´m not able to generate code
[Android Software/Hacking General [Developers Only]] piflechien:
Apparently HTC has rewritten some parts of bluetooth stack. The bitpool value is set in the BTLD module. (htc specific, you won't find it in cyanogen mod). The binary is located in \system\bin\btld

You might wanna try to hex edit this file to change the 32 value to something like 53
[Android Software/Hacking General [Developers Only]] CzarDestructo:
Anyone willing to work on this problem for a bounty? I want this working on my Vibrant, badly. Willing to pay for it. If you have a method that works please PM me.
[Android Software/Hacking General [Developers Only]] DArkwIng24:
source code from HTC

here you can find source code for HTC phones. http://developer.htc.com/

found libary for blueZ for Desire.

i have sendt a mail to HTC trying to get them to come look at this tread and possible work with us on this problem.

I did the same and sendt a mail to Samsung on this matter since my Galaxy tab also has this problem.

if we need to recompile the bluez libary to get this better we need the manufacturer to do this and relase a update for that.
[Android Software/Hacking General [Developers Only]] mcseven:
same here, I also described the problem to the support pointing to this thread, perhaps it helps if more people write to them so that they know it's not just a minority ;) Cheers...
[Android Software/Hacking General [Developers Only]] DArkwIng24:
we need more respons in Google developer thread

we need more respons in Google developer thread on this matter.

go to this tread and star it so that google notis it

http://code.google.com/p/android/issues/detail?id=9888&q=a2dp&colspec=ID Type Status Owner Summary Stars

click on the start in the upper left of the thread
[Android Software/Hacking General [Developers Only]] DArkwIng24:
HTC has given response

"Thank you for contacting us.

Kristian, I will be able to escalate this issue for further investigation, but I will need the serial number or IMEI number of your Desire phone before I can do that."

detailed description and links to this forum and tips about the Cyanogen code for bluetooth stack, and IMEI numbers, build number for my desire and HTC Magic (magic has very good a2dp quality) lets hope samsung does the same.
[Android Software/Hacking General [Developers Only]] white-energy:
So.. any response from htc ?
[Android Software/Hacking General [Developers Only]] mcseven:
Hi all, HTC replied a few minutes ago, unfortunately nothing of substance:

Which essentially translates to "Thank you, I received your suggestion, sorry for the inconvenience, Goodbye."; so as I said, nothing of substance... Cheers, Seven
[Android Software/Hacking General [Developers Only]] white-energy:
Have you tried to send them an email with insult.. i guess they would fix that bug in mins xD
[Android Software/Hacking General [Developers Only]] DArkwIng24:
no reply as of yet

still no reply. but i going to send them a update and see if we can spam them with this problem often so that they evenutally will have to look at it.

I think every one should use the HTC service contact to spam them with this problem, but in a diplomatic way. do not use insults, that gets us nowhere
[Android Software/Hacking General [Developers Only]] allroy1975:
I don't know what I'm doing or what I'm looking for, but everyone keeps saying our bitpool is set to 32 and setting it higher (54) will fix it, but no one knows how on an android, except Cyanogen... apparently.

I have an EVO, so I downloaded the blueZ source for the EVO. I used notepad++ to search through all the files in the source for "bitpool = 32" and found instances in 2 files. if we just change that to bitpool = 54 and recompile it, will it work?

I'm not a developer, but this issue REALLY bothers me. I got a new car radio and spent extra $ on it JUST so I could stream BT music over it. The fact that the sound is sub-par at best is more than a little disappointing.

I also sent cyanogen a PM here on XDA and asked if he could give me some suggestions on where to start...is it just a recompiled bluetooth stack, or did he develop it? if not who did? stuff like that.

Hopefully we can get something figured out.
[Android Software/Hacking General [Developers Only]] allroy1975:
if anyone who knows what they're doing and can use this info here's the 2 files I found in the blueZ files that had the bitpool = 32 in them:

C:\bluez\sbc\sbc.c (1 hits)

Line 955:	sbc->bitpool = 32;

C:\bluez\sbc\sbcenc.c (1 hits)

Line 240:	int i, opt, subbands = 8, bitpool = 32, joint = 0, dualchannel = 0;

Like I said...I don't know what to do with that.

I compiled a few versions of MAME before..but something tells me this is a little different. :p
[Android Software/Hacking General [Developers Only]] jonboyuk:
I too have tried Cyanogen's new Gingerbread build on my HD2 and for the first time, I heard crisp, quality A2DP over my phone. It was awesome. However, I want to continue using my Froyo sense build so really would like to see a fix. It's possible....we just need a genius or 2 to work it out! I wonder if Cyanogen is contactable?
[Android Software/Hacking General [Developers Only]] allroy1975:
I pm'd him here on xda. No response.

I just checked out the newest adw ex launcher on my sense rom last night. It was very similar to launcher pro, so I nandroided that config and started over with cyanogen again. It's REALLY nice. The problem I had with cyanogen was launcher pro didn't run well for me. Adw ex is tearing it up. There are some really minor things I miss (I was really used to swyping my lock screen down instead of left to right, but there are a lot of really nice features. For now I'm just gonna stick with cyanogen. :-)
[Android Software/Hacking General [Developers Only]] bluefrog:
This thread surprised me a bit. I came from WinMo phones and bitpool tweaking as well.

BUT I've got a Dell Streak and the A2DP has been pretty awesome since 2.1. I've a Pioneer BT Head Unit in the car and you'd really struggle to tell it wasn't a CD playing.

So how come the Streak is hot at A2DP and other devices apparently aren't? :s

btw currently running StreakDroid 1.5.3 but when it was on 2.1 that was stock O2
[Android Software/Hacking General [Developers Only]] heyjoe66:
i've broken my neck trying to compile it in windows

help!!!
[Android Software/Hacking General [Developers Only]] mcheffe:
You're probably better off doing this on Linux. Install VirtualBox on Windows then create a new VM and load Ubuntu. It will probably take less time than fixing issues in Windows.

BTW, I never successfully ran bluez from my Froyo build. I got it to compile fine but ran into problems when the files were copied to my device. If you figure out the complete set of files necessary to get around dependency issues please post the list.

Sent from my HTC HD2
[Android Software/Hacking General [Developers Only]] kimw:
this thread is hot as hell!

someone please fix this issue... as far as i can see you guys are pretty close to it. we need to somehow push this thread.

good luck for your complie thing (i'm an absolute programming nerd).
[Android Software/Hacking General [Developers Only]] white-energy:
Can anyone make a tutorial for this bitpool thing :S
[Android Software/Hacking General [Developers Only]] jonboyuk:
Not sure anyone's fixed it yet to make a tutorial!!
[Android Software/Hacking General [Developers Only]] bkrodgers:
Unfortunately, I don't think we're as close as we may think. All of the lines that people are suggesting be changed are exactly the same in the HTC release of the Bluez source and the Bluez source that is in CM. In fact, the majority of the differences in the Bluez source that HTC released are changes that appear to be intended to bypass some of this code entirely and route functionality instead to the proprietary BTLD executable. That's broadcom's closed source stack, I believe. I believe that's where the bitpool is set. You can actually find the string that formats the "alloc : 3, blk len 240, chmode:15, bitpool 32:2, subbands 12" message in the btld executable. I haven't found exactly where it's setting it to that though. In other words though, I'm not sure CM explicitly "fixed" it per se. They're using a BT stack that has it right (and is open source), instead of the broadcom stack that doesn't have it right (and is closed source).

Hope is not lost though. The stock BT stack without any of Broadcom's stuff seems to work just fine on CM. The question though is why HTC chose to use Broadcom's stack at all. Is there something in the Sense ROMs that would prevent us from compiling an unmodified BlueZ stack that doesn't use BTLD at all and dropping it in? I'm certainly willing to try that at some point. If we can get that to work at all, I would expect it to fix the problem. But it's also possible BT just won't work.

The other approach is to try to modify the BTLD executable, if we can figure out where it's setting it to 32. I'm not as experienced with modifying compiled code directly, though I can certainly try to learn. I'm more intrigued by the idea of just replacing BTLD entirely, if that's possible. I don't think people have been complaining of BT problems on CM, but I just hope there's nothing in some other closed source part of the Sense ROM that will prevent it from working.
[Android Software/Hacking General [Developers Only]] sandy16888:
Thankyou,good.
[Android Software/Hacking General [Developers Only]] kimw:
another great posting.

isn't this a developers forum? there must be anybody out there that is able to try this "modifying compile code" thing out.
[Android Software/Hacking General [Developers Only]] ssvb:
Interesting. Does this BTLD just set bitpool settings or it also implements SBC codec? Using just 32 for bitpool is definitely not good for quality, but for example audible clicks which some people complain about might be caused by some bugs in the codec and actually unrelated to bitpool.

Also are there any bad A2DP audio quality reports for the devices which use the stock opensource bluez implementation? Being one of the contributors to the opensource bluez SBC codec myself, I'm a bit worried about the audio quality issues on android phones reported all over the net.
[Android Software/Hacking General [Developers Only]] syntheticexctasy:
I am using a stock DK28 Samsung Epic, and still haven't figured out how to improve the a2dp sound quality, though some say using a cyanogenmod rom/kernel combo will solve the problem, however, this rom is still pretty limited in functionality for the epic specifically, so I haven't tried this yet.
[Android Software/Hacking General [Developers Only]] andrewilley:
Someone else who would love an answer to this. I like my Desire-Z with Sense so don't really want a non-sense ROM, but would love Bluetooth stereo to work properly!

Can't believe there isn't an Android option for this to be honest, was used to WinMo 6 where I could alter it very easily.

Andre
[Android Software/Hacking General [Developers Only]] bkrodgers:
I haven't figured out yet if it still uses the SBC codec from bluez or if it has its own. But I can say that CM (which uses bluez) does not have any quality issues reported. It may be that BTLD just is setting a low bitpool but is still letting SBC handle the codec duties.

I haven't had time to look into the option of stripping out BTLD much. I'm also playing with CM7 at the moment, but I may come back to this.
[Android Software/Hacking General [Developers Only]] BWA80:
Hi!

I hope the brain work is still going on with this issue... and is not forgotten, untill the final solution is digged out.

If you can do this tweaking on winmo, i would think it is possible here too (my wishful thinking).

In somebody i trust to find the path of great bluetooth audio...
[Android Software/Hacking General [Developers Only]] mike freegan:
I second the above. this is a massive issue, and it is embarrassing that it is still and issue for android.
[Android Software/Hacking General [Developers Only]] piflechien:
Is the problem also present on the new HTC "S" line product ?
[Android Software/Hacking General [Developers Only]] eumecon:
Unfortunately yes :(

I have an Incredible S and came across this thread while trying to understand why the audio was so bad via bluetooth (I don't really rate it via the headphone jack either to be honest)

The sound is very distorted at high frequency, to the extent it even hurts to listen to it.

Tested using Sony Ericsson MW600 headphones, and a JVC KD-R711 car stereo. Quality of both are excellent when connected to a SE Xperia Phone.

Email sent to HTC support as a "me too" in the hope they wake up to this. I cannot believe it is such a big issue. Unfortunately for me it's a dealbreaker. The HTC is going back, but will re-buy it if there is any progress. Good luck guys!
[Android Software/Hacking General [Developers Only]] jonboyuk:
FYI, this is all fixed in Gingerbread. HTC are rolling it out to most of their newer Android phones (inc Desire, Desire HD etc)! I've tried gingerbread and it fixed it for me :)
[Android Software/Hacking General [Developers Only]] BWA80:
Hi!

So all is fixed in gingerbread? Is the sound quality just better or can you actually tweak the settings?

Like:

- Joint Stereo

- Bitpool

- Maximum supported bitpool

- Minimum supported bitpool

- Sample rate

(you can tweak alot of settings in winmo with a app called, Advanced config tool 3.3, it would be great to have this app on android)

Thanks!!
[Android Software/Hacking General [Developers Only]] piflechien:
Gingerbread does fix the problem, I agree. The thing is that HTC doesn't use the standard Android "drivers" for bluetooth, they have created and compiled a whole module of their own. So we don't know if they have merged these changes into their code unless someone have access to an HTC Sense ROM based on android > 2.3.2
[Android Software/Hacking General [Developers Only]] bkrodgers:
Indeed. Froyo was fine as well (at least it was with Cyanogen). If we're seeing HTC shipped GB roms that have this fixed, that's a very good sign. But GB itself won't necessarily mean it gets fixed. Basically, three choices:

1. HTC switches to using the default BlueZ implementation. This clearly can work with our hardware, since CM does it.

2. HTC works with Broadcomm to fix the problems with their proprietary stack.

3. HTC keeps using the flawed Broadcomm proprietary stack.

Up until now, they've gone with #3. If they're going to either #1 or #2, that's great news. But we can't base any conclusion on what someone might be seeing in CM7 or any other AOSP GB ROM, as HTC could continue to overwrite a working stack with a bad one.
[Android Software/Hacking General [Developers Only]] Chapell:
Well, Gingerbread for Desire didn't fix for me the distortion in high frequencies.
[Android Software/Hacking General [Developers Only]] Cartmanation:
Gingerbread is actually the same problem. It appears that the cyanogen ROMS is solved.

Can you confirm?

There any way to check?
[Android Software/Hacking General [Developers Only]] Chapell:
It is confirmed that Cyanogen fixed this, but any existing Sense ROM has these problems (for me at least). Strange, because my girlfriend's HTC Legend is perfect with both 2.1 and 2.2 Sense, only my Desire...