[pulseaudio-discuss] [PATCH v8 07/12] bluetooth: Add A2DP aptX and aptX HD codecs support

Pali Rohár pali.rohar at gmail.com
Fri Apr 19 10:52:56 UTC 2019


On Friday 19 April 2019 11:41:22 Tanu Kaskinen wrote:
> On Sat, 2019-04-06 at 11:16 +0200, Pali Rohár wrote:
> > This patch provides support for aptX and aptX HD codecs in bluetooth A2DP
> > profile. It uses open source LGPLv2.1+ licensed libopenaptx library which
> > can be found at https://github.com/pali/libopenaptx.
> > 
> > aptX for s24 stereo samples provides fixed 6:1 compression ratio and
> > bitrate 352.8 kbit/s, aptX HD provides fixed 4:1 compression ratio and
> > bitrate 529.2 kbit/s.
> > 
> > According to soundexpert research, aptX codec used in bluetooth A2DP is no
> > better than SBC High Quality settings. And you cannot hear difference
> > between aptX and SBC High Quality, aptX is just a copper-less overpriced
> > audio cable.
> > 
> > aptX HD is high-bitrate version of aptX. It has clearly noticeable increase
> > in sound quality (not dramatic though taking into account the increase in
> > bitrate).
> > 
> > http://soundexpert.org/news/-/blogs/audio-quality-of-bluetooth-aptx
> > ---
> >  configure.ac                            |  36 +++
> >  src/Makefile.am                         |   6 +
> >  src/modules/bluetooth/a2dp-codec-aptx.c | 445 ++++++++++++++++++++++++++++++++
> >  src/modules/bluetooth/a2dp-codec-util.c |   8 +
> >  4 files changed, 495 insertions(+)
> >  create mode 100644 src/modules/bluetooth/a2dp-codec-aptx.c
> 
> > +static bool can_accept_capabilities_common(const a2dp_aptx_t *capabilities, uint32_t vendor_id, uint16_t codec_id) {
> > +    if (!(capabilities->frequency & (APTX_SAMPLING_FREQ_16000 | APTX_SAMPLING_FREQ_32000 |
> > +                                     APTX_SAMPLING_FREQ_44100 | APTX_SAMPLING_FREQ_48000)))
> > +        return false;
> > +
> > +    if (A2DP_GET_VENDOR_ID(capabilities->info) != vendor_id || A2DP_GET_CODEC_ID(capabilities->info) != codec_id)
> > +        return false;
> > +
> > +    if (!(capabilities->channel_mode & APTX_CHANNEL_MODE_STEREO))
> 
> Why is mono support not implemented? Is it a limitation of libopenaptx?
> It's not a big shortcoming, but it would be nice to support mono too.

It is limitation of libopenaptx. aptX in bluetooth stores in some bits
parity checks and I was not able to find any mono encoded sample of
aptX. So I do not know how aptX mono should be properly encapsulated in
bluetooth a2dp. And for obvious reason there is no (public)
documentation about aptX on Internet.

So once somebody shows us how aptX mono for bluetooth a2dp looks like I
can implement missing mono support in libopenaptx and in pulseaudio.

> > +static size_t decode_buffer(void *codec_info, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed) {
> > +    struct aptx_context *aptx_c = (struct aptx_context *) codec_info;
> > +
> > +    const uint8_t *p;
> > +    uint8_t *d;
> > +    size_t to_write, to_decode;
> > +
> > +    p = input_buffer;
> > +    to_decode = input_size;
> > +
> > +    d = output_buffer;
> > +    to_write = output_size;
> > +
> > +    while (PA_LIKELY(to_decode > 0)) {
> 
> Is it intentional that encode_buffer() checks both to_encode and
> to_write in the while loop condition, but decode_buffer() only checks
> to_decode? If so, why does encode_buffer() need to be extra careful but
> decode_buffer() doesn't?

These checks are similar/same as in SBC codec code. And SBC code was
there prior to my work. So personally I do not know.

-- 
Pali Rohár
pali.rohar at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20190419/4262832f/attachment.sig>


More information about the pulseaudio-discuss mailing list