Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDAC issue with bluez-alsa 4.0.0 #3

Open
sydragos opened this issue Apr 27, 2023 · 9 comments
Open

LDAC issue with bluez-alsa 4.0.0 #3

sydragos opened this issue Apr 27, 2023 · 9 comments

Comments

@sydragos
Copy link

sydragos commented Apr 27, 2023

Hey, decided to open a separate issue to track it better.

Build bluez-alsa with:
../configure --enable-aac --enable-ofono --enable-aptx --enable-aptx-hd --with-libopenaptx --enable-ldac --enable-debug --enable-cli --with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib

The syslogs appear identical when switching between aptX-HD and LDAC.
But this is interesting:

pi@moode:~ $ bluealsa-cli -v info /org/bluealsa/hci0/dev_0C_C4_***/a2dpsnk/source
Device: /org/bluez/hci0/dev_0C_C4_***
Sequence: 9
Transport: A2DP-sink
Mode: source
Format: S32_LE
Channels: 2
Sampling: 96000 Hz
Available codecs: SBC AAC aptX aptX-HD
Selected codec: LDAC
Delay: 15.0 ms
SoftVolume: Y
Volume: L: 127 R: 127
Muted: L: N R: N

So even if LDAC was negotiated with the phone, it doesn't actually appear here as so. Moreover, I can use this command to change to any other codec except LDAC:

bluealsa-cli codec /org/bluealsa/hci0/dev_0C_C4_***/a2dpsnk/source SBC
bluealsa-cli codec /org/bluealsa/hci0/dev_0C_C4_***/a2dpsnk/source LDAC
bluealsa-cli: E: ../../../utils/cli/cli.c:447: CMD "codec": Couldn't select BlueALSA PCM Codec: SEP codec not available

But it was compiled in as mentioned in the readme:

pi@moode:~ $ bluealsa-cli status
Service: org.bluealsa
Version: v4.0.0
Adapters: hci0
Profiles:
  A2DP-source : SBC AAC aptX aptX-HD LDAC
  A2DP-sink   : SBC AAC aptX aptX-HD LDAC

pi@moode:~ $ bluealsa -h
Usage:
  bluealsa -p PROFILE [OPTION]...

Available BT profiles:
  - a2dp-source Advanced Audio Source (v1.3)
  - a2dp-sink   Advanced Audio Sink (v1.3)
  - hfp-ofono   Hands-Free AG/HF handled by oFono
  - hfp-ag      Hands-Free Audio Gateway (v1.7)
  - hfp-hf      Hands-Free (v1.7)
  - hsp-ag      Headset Audio Gateway (v1.2)
  - hsp-hs      Headset (v1.2)

Available BT audio codecs:
  a2dp-source:  SBC, AAC, aptX, aptX-HD, LDAC
  a2dp-sink:    SBC, AAC, aptX, aptX-HD, LDAC
  hfp-*:        CVSD

pi@moode:~ $ bluealsa-aplay -L
bluealsa:DEV=0C:C4:***,PROFILE=a2dp,SRV=org.bluealsa
    Pixel 7, trusted phone, capture
    A2DP (LDAC): S32_LE 2 channels 96000 Hz

EDIT: Using latest bluez-alsa or "--with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib" doesn't change anything. Using recompiled kernel with your changes (but moode's original kernel modules, otherwise no audio out).

@anonymix007
Copy link
Owner

anonymix007 commented May 1, 2023

  1. Write Raspberry OS Lite (64-bit) to USB Flash (I've used rpi-imager and 16 GiB USB drive)
  2. Build kernel according to official instructions with patch from README.md applied
  3. Connect via ssh and run build script (see README.md)
  4. sudo bluealsa -p a2dp-sink -c LDAC
  5. In another ssh window run pairable on and discoverable on in bluetoothctl, pair your phone once and later use bt-agent --capability=NoInputNoOutput &
  6. bluealsa-aplay

Now it started playing music. There seems to be a bug with changing sampling rate in bluealsa-aplay, but it's definitely issue with BluezALSA, not with my lib. After changing sample rate on phone from i.e. 96 kHz to 48 (or changing codec), music will be still played like with 96 kHz, so constant ALSA playback PCM underrun will be reported until bluealsa-aplay is restarted.
UPD: this only happens in qemu and rpi os lite, so some resampling alsa component must be missing.

Report your issue to whatever distro you're using, something is clearly misconfigured.

@sydragos
Copy link
Author

sydragos commented May 1, 2023

Do you think there could be an issue with 32 vs 64bit images? I will rebuild/retry on an Rpi OS Lite, and report back.

@anonymix007
Copy link
Owner

That might be the case, but it's unlikely.
How do you run bluealsa? It should be sudo bluealsa -p a2dp-sink -c LDAC

@sydragos
Copy link
Author

sydragos commented May 1, 2023

I run it with multiple codecs so I can select on my phone later: -c LDAC -c SBC -c aptx-HD
Recompiled LDAC with your instructions, it's the only codec that doesn't play any sound (I2S or HDMI speakers).

Tried on Moode and Rpi Lite OS. 32 vs 64bit board issue?

Edit: please let me know how to debug further...

@anonymix007
Copy link
Owner

anonymix007 commented May 1, 2023

I'd say it's Moode issue, but if you're getting same issue with RPi OS Lite, it might be a problem with I2S or HDMI speakers (LDAC is 96 kHz, other codecs are 44.1/48, so maybe you DAC isn't properly configured). Try 3.5 mm audio output, that's what I've used with my RPi 4

@sydragos
Copy link
Author

sydragos commented May 1, 2023

The Pi Zero W has no output jack. I did try putting down the sampling frequency to 44.1 or 48kHz, I see a change in the bluez-alsa logs, but no sound is coming out. What other commands/logs could I look into?

@anonymix007
Copy link
Owner

Did you restart everything after changing frequency? bluez-alsa can force everything to be 44.1 kHz IIRC, so try that or remove temporarily disable 96 and 88.2 kHz sampling rates in source code. You can also try changing bitrate or using different phone.

The best way to see what's going on is to run dumpcap to capture Bluetooth packets, this will help understand why is there no sound. You can write simple program to parse the pcap file (or just export it into json and parse it) and feed the data into LDAC decoder (see ldacdec.c as a reference). To turn on debugging info in libldacdec, uncomment CFLAGS += -DDEBUG_ADAPTATION line in makefile and rebuild. It will print a lot of useful information.

Also, was the MTU set properly by kernel? bluez-alsa should print it

@sydragos
Copy link
Author

sydragos commented May 2, 2023

Is this the MTU log line?
bluealsa: [20744] D: ../../src/ba-transport.c:724: A2DP socket MTU: 14: R:672 W:1024

With the modded kernel and modules I see it as:
bluealsa: [1371] D: ../../src/ba-transport.c:724: A2DP socket MTU: 14: R:1021 W:1024

@anonymix007
Copy link
Owner

Yes, that's correct. Modified kernel seems to do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants