Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Instruction Guide Moode 9: Add AAC bluetooth codec support
#1
Moode 9 already has built-in support for a wide range of common bluetooth codecs (SBC, aptX, aptX-HD both as source and sink; LDAC just as source) via bluez-alsa. Moode version 9.0.4 includes bluez-alsa in version 4.2.0.

AAC support (e.g. widely used by Apple devices) is missing, however, since the necessary codec library libfdk-aac2 is marked as "non-free" in Debian Bookworm so that it is not allowed to distribute binaries linking against it.

The following guide shows how to manually add the missing AAC codec support (both as source and sink) by building a modified version of Moode's bluez-alsa package. The resulting .deb files are finally installed via apt like any other normal package. They can easily be copied to other (fresh or existing) installations of Moode to directly install them there without the need to rebuild every time. Note also that there should not be any side effects on future in-place updates of Moode other than that the modified package might be upgraded to a newer, unmodified bluez-alsa version.


The build process is performed directly in Moode using ssh access, e.g. on a fresh installation:

1) After logging into Moode via ssh, we start with installing the necessary build dependencies:

Code:
# update package repository
sudo apt update

# install necessary build dependencies
sudo apt install dh-exec python3-docutils libasound2-dev libbluetooth-dev libfreeaptx-dev libsbc-dev liblc3-dev libldacbt-enc-dev libldacbt-abr-dev libmp3lame-dev libmpg123-dev libspandsp-dev libsystemd-dev libfdk-aac2 libfdk-aac-dev


2) Then we download the bluez-alsa source package to the current directory and change into its configuration directory:

Code:
# download bluez-alsa source package
apt source bluez-alsa

# change to its configuration directory
cd bluez-alsa-4.2.0/debian


3) Two files need to be modified here - rules and changelog (e.g. using nano <filename>):

- File rules:

Add a flag for the AAC codec at the end of the CONFIGURE_FLAGS section so that it reads:

Code:
CONFIGURE_FLAGS := \
        --with-libfreeaptx \
        --enable-aptx \
        --enable-aptx-hd \
        --enable-faststream \
        --enable-lc3-swb \
        --enable-ldac \
        --enable-mp3lame \
        --enable-mpg123 \
        --enable-msbc \
        --enable-ofono \
        --enable-systemd \
        --enable-manpages \
        --enable-debug \
        --enable-cli \
        --enable-aac


- File changelog:

Edit the version string in the first line of the file to distinguish it from the version provided by Moode, e.g. by adding "+aac" to the end of the version string, resulting in:

Code:
bluez-alsa (4.2.0-2moode1+aac) UNRELEASED; urgency=medium


4) Build the modified package:

Code:
# change back to the directory bluez-alsa-4.2.0/
cd ..

# build the modified package
dpkg-buildpackage -us -uc

# change back to the parent directory
cd ..


If the build process was successful, the parent directory of bluez-alsa-4.2.0/ should now contain a set of modified .deb packages. The following two files are the important ones, as only these two are necessary for the final installation step (which could as well be performed on a separate Moode installation - just copy these two to the new destination):

Code:
bluez-alsa-utils_4.2.0-2moode1+aac_arm64.deb
libasound2-plugin-bluez_4.2.0-2moode1+aac_arm64.deb


5) Install the modified .deb packages via apt and finally reboot:

Code:
# install modified packages from local source
sudo apt install ./bluez-alsa-utils_4.2.0-2moode1+aac_arm64.deb ./libasound2-plugin-bluez_4.2.0-2moode1+aac_arm64.deb

# reboot
sudo reboot


The AAC codec should now be used automatically when a supported bluetooth device is connected.


Final notes:

- You can easily check which codecs are supported by bluez-alsa using the command

Code:
bluealsa-cli status


- After connecting a bluetooth device you can also check which codec is actually in use using the command

Code:
bluealsa-cli -v list-pcms


- As the modification was installed as a package, it can easily be uninstalled by reinstalling Moode's original version (currently version 4.2.0-2moode1).

Code:
sudo apt install bluez-alsa-utils=4.2.0-2moode1 libasound2-plugin-bluez=4.2.0-2moode1


Best regards
Jens
Reply
#2
Thank you very much for this guide, it works flawlessly!


Code:
Service: org.bluealsa
Version: v4.2.0
Adapters: hci0
Profiles:
 A2DP-source : SBC AAC aptX aptX-HD LDAC
 A2DP-sink   : SBC AAC aptX aptX-HD
Code:
/org/bluealsa/hci0/dev_80_54_9C_0C_5F_A4/a2dpsnk/source
Device: /org/bluez/hci0/dev_80_54_9C_0C_5F_A4
Sequence: 1
Transport: A2DP-sink
Mode: source
Running: true
Format: S16_LE
Channels: 2
Sampling: 44100 Hz
Available codecs: aptX:4f000000010022
Selected codec: AAC:800104835b60
Delay: 15.0 ms
DelayAdjustment: 0.0 ms
SoftVolume: true
Volume: L: 77 R: 77
Muted: L: false R: false
Reply
#3
@jenzd  thanks  Smile

Code:
funkster@moodepod:~ $ bluealsa-cli status
Service: org.bluealsa
Version: v4.2.0
Adapters: hci0
Profiles:
 A2DP-source : SBC AAC aptX aptX-HD LDAC
 A2DP-sink   : SBC AAC aptX aptX-HD

I'm guessing that after every in-place 9.x update we will have to rebuild and reinstall from scratch, yes?
Reply
#4
@funkster

I haven’t looked at the code recently, so don’t hold me to this, but I expect you can save and keep reinstalling the altered bluez-alsa package until such time as Tim bumps moOde to a new version of bluez-alsa (currently 4.2.0) or the libraries on which the build is dependent change significantly. Anyway, there no harm in trying the same build. This guide tells how to revert if necessary.

Regards,
Kent
Reply
#5
(11-14-2024, 12:38 PM)funkster Wrote: I'm guessing that after every in-place 9.x update we will have to rebuild and reinstall from scratch, yes?

No, that's actually not necessary as long as Tim does not bump Moode to a newer version of bluez-alsa (which he hasn't for quite some time).

The version string of the modified package "4.2.0-2moode1+aac" is technically higher than the original version "4.2.0-2moode1". It's therefore not overwritten/downgraded during the in-place update.

Even if you decide to reinstall Moode 9.x from scratch it is not necessary to rebuild the package. Just save the two .deb files bluez-alsa-utils_4.2.0-2moode1+aac_arm64.deb and libasound2-plugin-bluez_4.2.0-2moode1+aac_arm64.deb of the old installation, copy them to the new Moode installation and run
sudo apt install ./bluez-alsa-utils_4.2.0-2moode1+aac_arm64.deb ./libasound2-plugin-bluez_4.2.0-2moode1+aac_arm64.deb
again.

That's the benefit of using packages. Smile  A rebuild should only be necessary if a future version of Moode upgrades the bluez-alsa package to a higher version or if there is a major bump of the underlying Raspberry Pi OS.

Cheers,
Jens
Reply


Forum Jump: