Configuring LDAC codec on Nixos for higher sound quality

LDAC (Low Delay Audio Codec) is a high-quality audio codec developed by Sony Corporation. It is designed to provide superior sound quality by transmitting audio data at a high bit rate over Bluetooth connections. LDAC supports a variety of sampling rates and bit depths, allowing for flexible usage across different audio devices.

Unlike other Bluetooth audio codecs, LDAC has the ability to transmit audio data at three different coding rates - 330kbps, 660kbps, and 990kbps - depending on the network conditions and the desired balance between sound quality and transmission stability.

LDAC also employs a unique adaptive bit rate control technique that adjusts the coding rate in real-time to ensure optimal performance. By enabling LDAC, users can experience high-resolution audio playback over Bluetooth with minimal loss in sound quality.

Validating the state of the current device

On NixOS using PulseAudio is possible to list all sinks with the following:

pactl list sinks

The list is extensive and was trimmed for sake of readability. For your device, find the following attributes which confirm which codec is actually being used:

Sink #89076
    Name: bluez_output.A4_77_58_4E_DC_D8.1
    Description: Soundcore Space A40
    Driver: PipeWire
    Properties:
        api.bluez5.address = "A4:77:58:4E:DC:D8"
        api.bluez5.codec = "aac"
        api.bluez5.profile = "a2dp-sink"

The following sends a message to the device for a JSON list of codecs, replace the device MAC for your device's MAC address.

pactl send-message /card/bluez_card.A4_77_58_4E_DC_D8/bluez list-codec
[{"name":"4","description":"AAC"},{"name":"1","description":"SBC"},{"name":"2","description":"SBC-XQ"}]

NixOS configuration

Here my following NixOS configuration, pulseaudioFull already contains all codecs, including LDAC.

sound.enable = true;
hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
};

programs.bash.shellAliases = { mixer = "pulsemixer"; };
environment.systemPackages = with pkgs; [

    pulseaudioFull
    # Console mixer
    pulsemixer

    # Equalizer on sterids
    easyeffects
];

Set the configuration

The configuration can be easily set by:

pactl send-message /card/bluez_card.A4_77_58_4E_DC_D8/bluez switch-codec '"ldac"'

Confirm the change

To confirm the change the previous stepps can be just repeated, or for easy of access, run the following snippet of code:

pactl list sinks | grep "api.bluez5.codec"
api.bluez5.codec = "ldac"

Notes

For Soundcore a40, it was required to install a new version of the firmware on the device to have the capability of using the ldac codec.