Audio quality and the Bluetooth SBC bitrate

1,018 views
Skip to first unread message

David Erickson

unread,
Dec 24, 2015, 2:08:10 PM12/24/15
to android-platform
All-
Because Nexus devices do not include the Apt-X codec I was interested in understanding what the available codecs are, and if they are configured for maximum quality.  After digging around I discovered that SBC is the only codec mandated in Bluetooth's A2DP, and included in AOSP/Nexus devices.  AOSP is configuring this codec to only advertise and select a maximum bitrate of 328kbps in joint stereo mode, matching the "high quality" suggested settings from way back in 2003, despite SBC being capable of delivering up to 512kbps.  See the following spec link, page 22 for the details:


There seem to be at least two problems currently with the AOSP code preventing a higher bitrate from being achieved:

1) The maximum bitpool used during negotiation is hard coded to match a 328kbps rate (53), so nothing over this can be negotiated
2) The SBC encoding rate is hard coded to be 328kbps, so even if a higher bitpool (and hence bitrate) is negotiated, it will still only use 328kbps. (Note this goes against Recommendation #2 in https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=262784)

I tested the following code tweaks on a Nexus 6P paired with my Honda Odyssey at the ~510kbps bitrate (I left a tiny buffer below 512), and it worked perfectly while the 6P's screen was on, but had some TX queue overflows with the screen off.  I am assuming the buffers and scheduling need tweaking for the higher bitrate while the device is coming in and out of sleep:

diff --git a/btif/co/bta_av_co.c b/btif/co/bta_av_co.c
index e410f14..ce642a9 100644
--- a/btif/co/bta_av_co.c
+++ b/btif/co/bta_av_co.c
@@ -62,7 +62,7 @@
 #define BTA_AV_CO_SBC_MIN_BITPOOL_OFF  5
 #define BTA_AV_CO_SBC_MAX_BITPOOL_OFF  6

-#define BTA_AV_CO_SBC_MAX_BITPOOL  53
+#define BTA_AV_CO_SBC_MAX_BITPOOL  85

 /* SCMS-T protect info */
 const UINT8 bta_av_co_cp_scmst[BTA_AV_CP_INFO_LEN] = "\x02\x02\x00";
diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c
index b6f3f0c..9af18f0 100644
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -152,7 +152,7 @@ enum {
 #endif

 /* Middle quality quality setting @ 44.1 khz */
-#define DEFAULT_SBC_BITRATE 328
+#define DEFAULT_SBC_BITRATE 510

 #ifndef BTIF_A2DP_NON_EDR_MAX_RATE
 #define BTIF_A2DP_NON_EDR_MAX_RATE 229

I'd like to propose the following:

1) Max bitpool is increased for all devices to ~85 during negotiation
2) 
- Change the default SBC bitrate to ~512kbps for all devices (This could be aggressive)
or
- Add an advanced settings menu for each paired Bluetooth device with a slider for setting the maximum SBC bitrate for that device
or
- Add an advanced settings menu to the Bluetooth settings with a slider for setting the maximum SBC bitrate for all paired devices

Also I'd be happy to work with anyone that is experienced with the buffering/scheduling code in the BT stack to fix the overflows that are occurring during screen off to improve the prototype.

Lastly, for anyone asking "why?", consider that we have ever-improving quality of source material, both in terms of bitrate and codec, as well as high quality output equipment.  If the bitrate of the SBC codec being used is negatively impacting the audio reproduction, and simply increasing the bitrate can minimize or eliminate this impact, it is worth doing.  Particularly if it has little to no impact on either the source or sink devices (TBD).

Thanks in advance for comments!
-David
Reply all
Reply to author
Forward
0 new messages