Bluetooth stack modifications to enhance audio high quality on headphones with out AAC, aptX, or LDAC codecs

Bluetooth stack modifications to enhance audio high quality on headphones with out AAC, aptX, or LDAC codecs


Before studying this text, it is suggested to learn the earlier one: Audio over Bluetooth: most detailed details about profiles, codecs, and gadgets / по-русски

Some wi-fi headphone customers word low sound high quality and lack of excessive frequencies when utilizing the usual Bluetooth SBC codec, which is supported by all headphones and different Bluetooth audio gadgets. A standard suggestion to get higher sound high quality is to purchase gadgets and headphones with aptX or LDAC codecs help. These codecs require licensing charges, that is why gadgets with them are dearer.

It seems that the low high quality of SBC is brought on by synthetic limitations of all present Bluetooth stacks and headphones’ configuration, and this limitation could be circumvented on any current gadget with software program modification solely.

SBC codec

SBC has numerous totally different parameters which are negotiated through the connection setup part:

  • Audio channel sort and quantity: Joint Stereo, Stereo, Dual Channel, Mono;
  • Number of frequency bands: 4 or 8;
  • Number of audio blocks in a single packet: 4, 8, 12, 16;
  • Quantization bit allocation algorithm: Loudness, SNR;
  • Maximum and minimal bit pool utilized in quantization course of: normally 2-53.

The decoder is required to help any mixture of those parameters. Encoder could implement solely part of them.

Existing Bluetooth stacks normally negotiate the next set of choices which I name «profile»: Joint Stereo, 8 bands, 16 blocks, Loudness, bitpool 2..53. This profile encodes 44.1 okayHz stereo audio with 328 kbps bitrate.

Bitpool is a parameter that modifications encoding bitrate: the upper it’s, the upper the bitrate, and therefore the standard. But actual bitpool worth corresponds to actual bitrate solely inside actual profile.

The bitrate can also be considerably affected by different parameters: audio channel sort, variety of frequency bands, variety of audio blocks. You can enhance the bitrate not directly by negotiating non-standard profiles, with out altering the bitpool.

$ bitrate = frac{8 times frame_length times sample_rate}{subbands times blocks} $

Bitrate calculation system

For instance, Dual Channel mode encodes channels individually, utilizing particular person bitpool for every channel, in contrast to Stereo or Joint Stereo, which use bitpool for each channels. Forcing the gadget to make use of Dual Channel as an alternative of Joint Stereo will get us virtually doubled bitrate of 617 kbps, with the identical bitpool worth of 53.

To me it feels that bitpool needs to be an inner variable. I assume that it’s an A2DP specification design fault that bitpool worth is just not sure to different codec parameters and solely outlined as an unbiased negotiated variable.

Fixed bitpool and bitrate values originated from really useful profile for prime quality audio. But the advice shouldn’t be the explanation to set the restrict on these parameters.

Bluetooth SBC profiles table

A2DP specification v1.2, which was energetic from 2007 to 2015, requires all decoders to work accurately with bitrates as much as 512 kbps:

The decoder of the SNK shall help all attainable bitpool values that don’t end in extra of the utmost bit price. This profile limits the accessible most bit price to 320kb/s for mono, and 512kb/s for two-channel modes.

No bitrate restrict said within the new model of the specification. It is assumed that trendy headphones with EDR help launched after 2015 can help bitrates as much as 730 kbps.

For some cause, all at present examined Bluetooth stacks (Linux (PulseAudio), Android, Blackberry and macOS) have synthetic restrictions of most bitpool parameter, which straight impacts the utmost bitrate. But this isn’t the most important downside, virtually all headphones additionally restrict the utmost bitpool worth to 53.

As I’ve already seen in my exams, most gadgets work tremendous on a modified Bluetooth stack with a bitrate of 551 kbps, with out interrupts and crackling. But such a bitrate won’t ever be negotiated beneath regular situations, with inventory Bluetooth stacks.

Bluetooth stack modification

Every A2DP-compatible Bluetooth stack ought to help Dual Channel mode, however there is not any strategy to pressure utilization of this mode.

Let’s add a swap to the consumer interface! I made patches for Android 8.1 and Android 9, which add full help for Dual Channel into the stack and into developer menu, and deal with Dual Channel mode as an extra «HD Audio» codec like aptX, AAC or LDAC by including a tick to the Bluetooth gadget settings Here’s what it appears like:

imageAndroid 9 patch
Android 8.1 patch

This checkbox toggles Dual Channel mode which is configured to make use of 551 kbps for EDR 3 Mb/s gadgets and 452 kbps for EDR 2 Mb/s gadgets.

This patchset has been merged into the next different firmwares:

  • LineageOS 15.1 (since 31 March, 2019) and 16.0 (since May 13, 2019)
  • Resurrection Remix (since May 14, 2019)
  • crDroid (since May 13, 2019)

Where did 551 and 452 kbps come from?

Bluetooth time division expertise is designed to effectively transmit giant fixed-size packets. Data switch happens in slots, the biggest variety of slots despatched in a single transmission is 5. There are additionally switch modes utilizing 1 or 3 slots, however not 2 or 4. You can switch as much as 679 bytes in 5 slots, at a connection velocity of two Mbps, and as much as 1021 bytes at a velocity of three Mbps. In 3 slots most quantity of knowledge is 367 and 552 bytes, respectively.

image

If we need to switch much less knowledge than 679 or 1021 bytes however greater than 367 or 552 bytes, the switch will nonetheless take 5 slots, and the transmission will take the identical period of time, which reduces the transmission effectivity.

image

44100 Hz audio encoded utilizing SBC in Dual Channel mode with bitpool = 38, 16 blocks in a body, 8 frequency bands, produces audio body of 164 bytes, with 452 kb/s bitrate.

Audio payload needs to be encapsulated into L2CAP and AVDTP transmission protocols, which deduct 16 bytes of overhead from the audio payload.

$begin{align*} framelength &= 4 + frac{subbands times channels}{2} +  & begin{cases} frac{blocks times channels times bitpool}{8} & text{if mono or dual channel mode}  frac{subbands+blocks times bitpool}{8} & text{if joint stereo mode}  frac{blocks times bitpool}{8} & text{if stereo mode}  end{cases} end{align*}$

One 5-slot audio transmission can include as much as 4 audio frames:

679 (EDR 2 mbit/s DH5) - 4 (L2CAP) - 12 (AVDTP/RTP) - 1 (SBC header) - (164*4) = 6

A single packet transmits as much as 11.7 ms of audio knowledge, which can be transmitted in 3.75 ms, and we now have 6 unused bytes left within the packet.

If you barely increase the bitpool, 4 audio frames can not be packed right into a single transmission. You’ll should ship 3 frames at a time, which reduces transmission effectivity, reduces the quantity of audio transmitted in a single packet, and can enhance likelihood for audio stutter beneath poor radio situations.

551 kbps bitrate for EDR 3 Mbps was chosen utilizing the identical precept: with Bitpool 47, 16 blocks per body, 8 frequency bands, the body dimension is 200 bytes, with a bit price of 551 kbps. Single transmission can bundle as much as 5 frames or 14.6 ms of music.

The algorithm for calculating all of the SBC parameters is sort of sophisticated, you possibly can simply make a mistake for those who attempt to calculate all of them manually, so I made an interactive calculator to assist those that :

btcodecs.valdikss.org.ru/sbc-bitrate-calculator

What is that every one for?

Contrary to well-liked perception of aptX sound high quality, in some circumstances it will probably produce worse audio high quality than SBC with a typical 328k bitrate.

SBC dynamically allocates quantization bits for frequency bands, appearing on a «bottom-to-top» foundation. If the entire bitrate was used for the decrease and center frequencies, the higher frequencies are «reduce off» (silenced).

aptX quantizes frequency bands with the identical variety of bits continuously, which makes it a relentless bitrate codec: 352 kbps for 44.1 okayHz, 384 kbps for 48 okayHz. It cannot «switch bits» to frequencies that want them most. Unlike SBC, aptX is not going to «reduce» frequencies, however will add quantization noise to them, lowering the dynamic vary of audio, and typically introducing crackles. SBC, quite the opposite, «eats the small print» — discards the quietest areas.

On common, in comparison with SBC 328k, aptX makes much less distortion in music with a large frequency vary, however on music with a slender frequency vary and a large dynamic vary SBC 328k typically wins.

Let us take into account a particular case, a piano recording. Here’s a spectrogram:

image

Most vitality locates within the 0-4 okayHz frequencies, and lasts as much as 10 okayHz.

The spectrogram of the file aptX file appears like this:

image

Here is SBC 328k:

image

It could be seen that the SBC 328k periodically fully reduce off the vary above 16 okayHz, and used all accessible bitrates for the frequency ranges beneath this worth. However, aptX launched extra distortions into the frequency spectrum audible by the human ear, which could be seen on the subtracted authentic audio spectrogram from the aptX spectrogram (the brighter, the extra distortion):

image

SBC 328k has launched much less distortion to the sign within the vary from 0 to 10 okayHz, and the remainder frequences had been сut:

image

485k bitrate was sufficient for SBC to avoid wasting the complete frequency vary, with out reducing off the bands.

image

SBC 485k produces a lot better leads to the vary of 0-15 okayHz on this pattern than aptX, and a smaller however nonetheless noticeable distinction at 15-22 okayHz (the darker, the much less distortion):

image

.

By switching to a high-bitrate SBC you’re going to get sound which is superior to aptX more often than not, on any headphones. On headphones with EDR 3 Mb/s help, 551 kb/s SBC produces sound that could be very near aptX HD.

Can we go even additional?

Android patchset has an extra choice to extend bitrate for EDR 2 mbps gadgets even additional. You can bump the bitrate from 452 kbps to 595 kbps, at the price of lowering the steadiness of the transmission in case of congested radio situations.

Just set the persist.bluetooth.sbc_hd_higher_bitrate variable to 1:

# setprop persist.bluetooth.sbc_hd_higher_bitrate 1

Extreme bit price patch is at present merged solely in LineageOS 15.1, however not in 16.0.

Compatibility with the gadgets

SBC Dual Channel is supported by virtually all headphones, audio system and automobile head items. This isn’t any surprise — the usual mandates its help in any decoding gadgets. There are a small variety of gadgets on which this mode causes issues, however these are very uncommon circumstances.

More particulars on appropriate gadgets could be discovered at 4pda and xda-developers.

Sound distinction comparability

I made an online service that encodes audio to SBC (in addition to to aptX and aptX HD) in actual time, proper within the browser. You can evaluate the sound of various SBC profiles and different codecs with out really transmitting audio by way of Bluetooth utilizing this service, on any wired headphones, audio system, and in your favourite music. You may also change the encoding parameters straight throughout audio playback.

btcodecs.valdikss.org.ru/sbc-encoder

Contacting Android builders

I attempted to contact many Bluetooth stack builders from Google, asking them to contemplate together with my patches to the principle Android department—AOSP, however didn’t obtain a single reply. My patches in Gerrit code evaluation system for Android haven’t obtained any feedback from anybody concerned within the improvement as properly.

I’d be glad if anybody may inform Google builders about this implementation of SBC HD for Android. The gerrit patchset is already old-fashioned (this is without doubt one of the earliest revisions), however I’ll replace it if builders are fascinated by my modifications (it isn’t simple for me to replace it, I haven’t got Android Q appropriate gadgets).

Conclusion

Users of LineageOS, Resurrection Remix and crDroid firmwares can improve Bluetooth audio high quality by ticking a checkbox in Bluetooth gadget settings. Linux customers may also get the next SBC bitrate by putting in the patch from Pali Rohár, which amongst different issues, provides help for the aptX, aptX HD and FastStream codecs.

HI-FI News

by way of Lobsters https://lobste.rs/

November 23, 2023 at 08:48PM