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

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

2023-11-23 13:41:49

Earlier than studying this text, it is strongly recommended to learn the earlier one: Audio over Bluetooth: most detailed information about profiles, codecs, and devices / по-русски

Some wi-fi headphone customers notice 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 assist. These codecs require licensing charges, that is why gadgets with them are costlier.

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

SBC codec

SBC has numerous totally different parameters which might be negotiated throughout the connection setup part:

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

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

Current Bluetooth stacks often 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 kHz 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. However precise bitpool worth corresponds to precise bitrate solely inside precise profile.

The bitrate can be considerably affected by different parameters: audio channel kind, variety of frequency bands, variety of audio blocks. You’ll be able to 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, Twin Channel mode encodes channels individually, utilizing particular person bitpool for every channel, not like Stereo or Joint Stereo, which use bitpool for each channels. Forcing the system to make use of Twin 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.

Fastened bitpool and bitrate values originated from really useful profile for prime quality audio. However the suggestion shouldn’t be the rationale 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 appropriately with bitrates as much as 512 kbps:

The decoder of the SNK shall assist all potential bitpool values that don’t lead to extra of the utmost bit price. This profile limits the out there 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’s assumed that fashionable headphones with EDR assist launched after 2015 can assist bitrates as much as 730 kbps.

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

As I’ve already seen in my assessments, most gadgets work high-quality on a modified Bluetooth stack with a bitrate of 551 kbps, with out interrupts and crackling. However such a bitrate won’t ever be negotiated underneath regular situations, with inventory Bluetooth stacks.

Bluetooth stack modification

Each A2DP-compatible Bluetooth stack ought to assist Twin Channel mode, however there isn’t any option to drive utilization of this mode.

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

image

Android 9 patch

Android 8.1 patch

This checkbox toggles Twin 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 Might 13, 2019)
  • Resurrection Remix (since Might 14, 2019)
  • crDroid (since Might 13, 2019)

The place did 551 and 452 kbps come from?

Bluetooth time division expertise is designed to effectively transmit giant fixed-size packets. Information switch happens in slots, the most important 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’ll be able to switch as much as 679 bytes in 5 slots, at a connection pace of two Mbps, and as much as 1021 bytes at a pace of three Mbps. In 3 slots most quantity of knowledge is 367 and 552 bytes, respectively.

image

If we wish to switch much less information 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 Twin 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 information, which shall be transmitted in 3.75 ms, and we’ve got 6 unused bytes left within the packet.

If you happen to barely increase the bitpool, 4 audio frames can not be packed right into a single transmission. You will need to 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 underneath 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 kind of difficult, you possibly can simply make a mistake in the event you 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’s that every one for?

Opposite to fashionable perception of aptX sound high quality, in some circumstances it could possibly produce worse audio high quality than SBC with a regular 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 «lower off» (silenced).

aptX quantizes frequency bands with the identical variety of bits consistently, which makes it a continuing bitrate codec: 352 kbps for 44.1 kHz, 384 kbps for 48 kHz. It may well’t «switch bits» to frequencies that want them most. In contrast to SBC, aptX won’t «lower» frequencies, however will add quantization noise to them, decreasing 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.

Allow us to think about a particular case, a piano recording. Here is a spectrogram:

image

Most power locates within the 0-4 kHz frequencies, and lasts as much as 10 kHz.

The spectrogram of the file aptX file seems to be like this:

image

Right here is SBC 328k:

image

It may be seen that the SBC 328k periodically utterly lower off the vary above 16 kHz, and used all out there bitrates for the frequency ranges under this worth. Nonetheless, aptX launched extra distortions into the frequency spectrum audible by the human ear, which might 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 kHz, and the remainder frequences had been сut:

image

See Also

485k bitrate was sufficient for SBC to save lots of your complete frequency vary, with out reducing off the bands.

image

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

image

Archive with original audio and SBC/aptX-encoded files.

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 assist, 551 kb/s SBC produces sound that may be very near aptX HD.

Can we go even additional?

Android patchset has an extra possibility to extend bitrate for EDR 2 mbps gadgets even additional. You’ll be able to bump the bitrate from 452 kbps to 595 kbps, at the price of decreasing the steadiness of the transmission in case of congested radio situations.

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

# setprop persist.bluetooth.sbc_hd_higher_bitrate 1

Excessive bit price patch is at the moment merged solely in LineageOS 15.1, however not in 16.0.

Compatibility with the gadgets

SBC Twin Channel is supported by virtually all headphones, audio system and automotive head models. That is no surprise — the usual mandates its assist in any decoding gadgets. There are a small variety of gadgets on which this mode causes issues, however these are very uncommon circumstances.

Extra particulars on appropriate gadgets might 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’ll be able to examine 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 too can change the encoding parameters immediately 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 think about together with my patches to the primary Android department—AOSP, however didn’t obtain a single reply. My patches in

Gerrit code review system for Android

haven’t acquired any feedback from anybody concerned within the improvement as effectively.

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

Conclusion

Customers of LineageOS, Resurrection Remix and crDroid firmwares can improve Bluetooth audio high quality by ticking a checkbox in Bluetooth system settings. Linux customers can even get the next SBC bitrate by putting in

the patch from Pali Rohár

, which amongst different issues, provides assist for the aptX, aptX HD and FastStream codecs.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top