Skip to content

Adds SBC XQ negotiated at the best of capabilities of the BT device

JP Guillemin requested to merge Hyperion/pulseaudio:SBC-XQ into master

SBC XQ is standard SBC codec operating at high bitrates and thus reaching the transparent audio transport quality of AptX (HD) and other proprietary codecs.

According to http://soundexpert.org/articles/-/blogs/audio-quality-of-sbc-xq-bluetooth-audio-codec , AptX quality can be reached either :

  • in STEREO MODE, with bitpool ~ 76
  • in DUAL CHANNEL MODE, with bitpool ~ 38 per channel

APTX-HD quality is achieved with values :

  • in STEREO MODE, with bitpool ~ 94
  • in DUAL CHANNEL MODE, with bitpool ~ 47 / channel

A2DP specification (A2DP SPEC) defines SBC parameters. These parameters are negotiated between the source (SRC) and the receiver (SNK) at connection time :

  • Audio channel mode : Joint Stereo, Stereo, Dual Channel, Mono : all modes are MANDATORY for the SNK according to A2DP specification
  • Number of subbands: 4 or 8 - both MANDATORY for the SNK implementation
  • Blocks Length: 4, 8, 12, 16 - all MANDATORY for the SNK implementation
  • Allocation Method: Loudness, SNR - both MANDATORY for the SNK implementation
  • Maximum and minimum bit pool : between 2 to 250, expressed in 8 bit uint (Unsigned integer, Most significant bit first) : -- A2DP spec v1.2 states that requires all SNK implementation shall handle bitrates of up to 512 kbps (which correspond to bitpool = 76). -- A2DP spec v1.3 doesn't specify any bitrate limit, and some high-end SNK devices announce bitpool between 62 and 94 (bitpool 94 = 551kbps bitrate).

These high end devices should not be limited to low bitrates because of arbitrary SRC bitpool limit.

The A2DP specification V1.3 provides RECOMMENDATIONS for bitpool implementation for the encoder of the SRC : it is required to support AT LEAST the following settings :

  • STEREO MODE : 53
  • MONO MODE : 31
  • DUAL CHANNEL : unspecified, so let's assume that the MONO value can be used : 31

In the implementation of this patch : bitpool IS ALWAYS NEGOCIATED, never forced, and the maximum value announced by the SNK device IS safely followed WHATEVER MAXIMAL BITPOOL VALUE IS ALLOWED ON SRC SIDE.

Radio capabilities are as follow : +-------------------------+-----------+-------+-----------+-------+ | Bluetooth speed EDR | EDR 2Mbps | | EDR 3Mbps | | +-------------------------+-----------+-------+-----------+-------+ | Speed (b/s) | 2097152 | | 3145728 | | | Radio slot length (s) | 0.000625 | | 0.000625 | | | Radio slots / s | 1600 | | 1600 | | | Slot size (B) | 163.84 | | 245.76 | | | Max payload/5 slots (B) | 676.2 | | 1085.8 | | | max bitrate (Kb/s) | 1408.75 | | 2262.08 | | +-------------------------+-----------+-------+-----------+-------+

We don't want the frames to be fragmented to preserve latency : so a frame should fit into a radio slot. Sampling freq has no impact on frame size, and resulting bitrate never exceed BT max capacity at 2Mbps : so Sample frequency doesn't need specific bitpool reduction.

+-------------------------+-----------+-------+-----------+-------+ | sampling Freq (Hz) | 44100 | 48000 | 44100 | 48000 | | bitpool / channel | 38 | 38 | 47 | 47 | | Frame length DUAL (B) | 164 | 164 | 200 | 200 | | Frame length JST (B) | 165 | 165 | 201 | 201 | | Frame length ST (B) | 164 | 164 | 200 | 200 | | bitrate DUAL CH (kb/s) | 452.025 | 492 | 551.25 | 600 | | bitrate JOINT ST (kb/s) | 454.78125 | 495 | 554.00625 | 603 | | bitrate STEREO (kb/s) | 452.025 | 492 | 551.25 | 600 | +-------------------------+-----------+-------+-----------+-------+

I propose the following safe maximal values (can be discussed) :

  • STEREO MODE : <= 94
  • MONO MODE : <= 38
  • DUAL CHANNEL : <= 38 (always inferior to any device capability, since 90% of them announce max bitpool = 53 and the remaining devices : more than 53. Very few announce ~ 40).

The negotiation policy is as follow :

  • Any SNK device announcing max bitpool > 53 is allowed to reach 94 (if the SNK device announce 57 then 57 will be used)
  • Any SNK device announcing max bitpool > 53 is offered STEREO MODES first, and DUAL CHANNEL as fall back
  • Any SNK device announcing max bitpool <= 53 is allowed to reach 53 (if the SNK device announce 47 then 47 will be used)
  • Any SNK device announcing max bitpool <= 53 is FIRST offered DUAL CHANNEL at bitpool 38, so that the 512 kbps is never exceeded (if the SNK device announce 47 then 38 will be used, if the SNK device announce 31 then 31 will be used)
  • Any SNK device announcing max bitpool <= 53 is THEN offered STEREO MODES if DUAL CHANNEL is announced unsupported (if the SNK device announce 47 then 47 will be used).
Edited by JP Guillemin

Merge request reports