DietPi RPi4 HDMI audio output limited to 16 bits

Hi @MichaIng

I seen lots of posts over the years about the Pi’s HDMI output being limited to 16 bits

And I have this limitation now

Are you able to reproduce this? And can fix?

Thanks

The onboard bcm2835_audio audio driver indeed supports 16 bits only. When you use the ALSA auto-conversion plugin, audio streams are downsampled automatically. This can be e.g. enabled via dietpi-config audio options, or use the plug PCM plugin in case you use a custom asound.conf/.asoundrc.

But I guess you would actually like to play e.g. 24 bit audio sources natively? Check out this issue: 24 bit audio output on Raspberry Pi 4 b model · Issue #4204 · raspberrypi/linux · GitHub
So while bcm2835_audio does not support it, the dedicated HDMI audio driver that comes with vc4-kms-v3d actually does.

dietpi-config explicitly enables and uses the bcm2835_audio for consistency, and as it does not depend on the KMS video stack, but you may want to test using the KMS-embedded one:

# Assure that the full KMS video stack is enabled, including its HDMI audio driver (there is a "noaudio" flag)
G_CONFIG_INJECT 'dtoverlay=vc4-f?kms-v3d' 'dtoverlay=vc4-kms-v3d' /boot/config.txt
# Disable bcm2835_audio
G_CONFIG_INJECT 'dtparam=audio=' 'dtparam=audio=off' /boot/config.txt
# Reboot for changes to take effect
reboot

As /etc/asound.conf should use the audio card 0, and with disabled bcm2835_audio the KMS HDMI audio card should become card 0, it should be used right away. But verify via aplay -l.

1 Like

Thanks @MichaIng

I got excited that this would be a quick fix,

I did all the above but see attached 2 screenshots

Now no audio playing at all.

:see_no_evil: :sweat_smile:. Okay the vc4-hdmi audio card appears as only one and card 0 as expected. /etc/asound.conf contains card 0 as PCM and control device, right?

Is there probably a volume control or toggle too low/disabled in alsamixer?

Also speaker-test or speaker-text -c 2 do not produce output?

And do you have the auto-conversion plugin enabled, just to rule out that another part of the audio stream format is not supported by that driver?

grep 'type plug' /etc/asound.conf

In case the above returns nothing (copy&paste the whole block at once into SSH, if possible):

cat << _EOF_ > /etc/asound.conf
pcm.!default {
	type plug
	slave.pcm {
		type hw
		card 0
		device 0
	}
}
ctl.!default {
	type hw
	card 0
}
_EOF_

It can currently not be enabled via dietpi-config, as this would revert to using bcm2835_audio.

1 Like

Hi @MichaIng

See attached screenshots

There’s no volume controls for alsamixer - is that expected .

And see speaker-test outout, Only 1ch ? Have you seen this before

And I copied entire block and still no music playing.

Is this issue only with RPi? Does your Odroid C2 play 24bit 192kHz on HDMI output ?

image

Not sure, no controls at all, hmm.

This is the default audio format produced by speaker-test: 48 kHz, 16 bits and 1 channel is obviously not natively supported by this sound driver. Now that you applied the auto-conversion plugin, the command should actually succeed and send some audio stream. Without this plugin, speaker-test -c 2 should have worked to have it producing a 2 channels stream.

I’ll test this on my RPi Zero. Generally it should behave similar.

I do not have an Odroid C2, but a few other SBCs. Generally I think the 16 bits is indeed a limitation of the RPi onboard sound card. Also this alternative KMS/VC4 HDMI audio device is not something which exists on other SBCs, and I never actually tried to configure it. Probably it requires 32 MiB GPU memory or more to not have the “cut-down” GPU firmware loaded.

Does this help (in case GPU memory is still 16 MiB)?

G_CONFIG_INJECT 'gpu_mem_1024=' 'gpu_mem_1024=32' /boot/config.txt
reboot

Oops So yesterday I copied your code with said speaker-text but now these tests are working. Both 1ch and 2ch output. See screenshots below

I ran the GPU memory code , maybe that helped

Only issue now is HQPlayer NAA on Dietpi doesn’t want to output 2ch and there is no sound. HQP reports 1ch

Whereas when I had the 16bit limit, HQPlayer was working fine for 8 channels audio 192kHz, just with the annoying 16bit limit.

Now that the speaker tests works, does it give a clue how to get NAA working?

Also, what is the cheapest SBC you have that is globally available, that has 24bit audio in HDMi working for you ?

I also just installed Shairport for a quick Airplay test

Airplay starts but No sound coming out. Then Airplay disconnects

Just like with HQPlayer NAA

Since the speaker-tests work, hopefully it means we are close ?

That is the magic of the auto-conversion plugin, which you enabled after you ran speaker-test yesterday. The 1 channel stream is now automatically converted to 2 channels, and other format parameters adjusted as well, if needed.

I guess it was not needed then.

Looks like both variants have their limitation. But it seems like HQPlayer or the NAA-Daemon auto-detects the hardware PCM and bypasses the auto-conversion/plug PCM.

Please check the software settings, especially that the output device is correctly specified: “default”, if possible. And since the control device has no controls, it must not be specified. Also in /usr/local/etc/shairport-sync.conf it can be specified, and Shairport Sync then uses it for volume control. As it is not possible, comment out the setting if set, so that it uses software-wise volume control.

Probably it makes sense to search for info or ask RPi engineers about the natively supported auto formats on both HDMI audio variants, and whether they can be configured (and whether it is expected to have ho vc4hdmi controls). With auto-conversion, all audio stream should work, but in the end you want the best quality, i.e. the stream which arrives at your HDMI peripheral is what matters.

1 Like

Thanks @MichaIng . I’ll investigate further

Also, what is the cheapest SBC you have that is globally available, that has 24bit audio in HDMi working for you ?

Hi @MichaIng

I picked up a cheap Odroid C4 to test.

The good news is 24bits is fine

But the bad news is 8channels does not work out of the box for the Odroid - only stereo,

but 8ch does work for the RPi4 out of the box :smile:

Here are some screenshots.

Any tips what this means?

See 8 channel speaker test below, It runs but AVR only shows stereo and sound is only from ch1 and ch2 speakers. Nothing out of the other 6 speakers

At least with Pi, you get multichannel 192kHz but limited to 16 bits.

Frustrating that C4 doesn’t work

How did you solve it eventually?

Nobody has had this solved.

With RPi4 , I have to set output to 16bits with TPDF dither enabled

Odroid C4 and N2 indeed have a quite complicated audio setup which I didn’t fully understand either. Via trial & error I was able to get 2 and 2.1 channel output working, and tried to explain it myself as far as I understood/interpreted the controls: https://github.com/MichaIng/DietPi/blob/dev/dietpi/func/dietpi-set_hardware#L2095-L2109

See the output of amixer scontrols or alsamixer for the available controls. There are these FRDDR sinks, which I interpreted as channels. IIRC there were these 3 only, but probably I missed something or there is another way to enable all 8 channels.

did you read this?

I am going to try.

2 Likes

Good fine, so it is a limitation of the RPi audio driver. Strange that 24 bits HDMI output is not available OOTB when it is so simple to add it.

1 Like

I am stuck here, any idea?

sudo ./build_kernel.sh


*** Can’t find default configuration “arch/arm64/configs/bcm2709_defconfig”!


make[1]: *** [scripts/kconfig/Makefile:94: bcm2709_defconfig] Error 1
make: *** [Makefile:704: bcm2709_defconfig] Error 2


*** Configuration file “.config” not found!


*** Please run some configurator (e.g. “make oldconfig” or
*** “make menuconfig” or “make xconfig”).


make: *** [Makefile:791: .config] Error 1

ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run ‘make oldconfig && make prepare’ on kernel src to fix it.

Makefile:748: include/config/auto.conf: No such file or directory
make: *** [Makefile:813: include/config/auto.conf] Error 1
cp: cannot stat ‘arch/arm/boot/dts/.dtb’: No such file or directory
cp: cannot stat 'arch/arm/boot/dts/overlays/
.dtb*’: No such file or directory
cp: cannot stat ‘arch/arm/boot/zImage’: No such file or directory

Here are the available configs: https://github.com/raspberrypi/linux/tree/rpi-6.1.y/arch/arm64/configs
For RPi 4 it would be bcm2711_defconfig.

1 Like

I am very glad to tell you all the problem was solved by the instruction, you can see the 24bits output below

However, the first compilation was not working because the build_kernel.sh in 2-in, 8-out DSP platform using the Raspberry Pi + HATs | diyAudio was for older version of diet-pi.

This is the correct build_kernel.sh

#!/bin/bash
#this script will build the kernel from the source in ~/kernel
#see for more info:

Kernel building - Raspberry Pi Documentation

#this script must be run as root or with sudo or will exit here:
if [ “$EUID” -ne 0 ]
then echo “Please run as root or using sudo”
exit
fi

#setup:
KERNEL=kernel8
make bcm2711_defconfig

#these commands build the kernel:
make -j4 Image modules dtbs
make modules_install
cp arch/arm64/boot/dts/broadcom/.dtb /boot/
cp arch/arm64/boot/dts/overlays/
.dtb* /boot/overlays/
cp arch/arm64/boot/dts/overlays/README /boot/overlays/
cp arch/arm64/boot/Image /boot/kernel8.img

And this is the result of uname -a after its done and reboot
root@DietPi:~/linux# uname -a

Linux DietPi 6.1.73-v8+ #2 SMP PREEMPT Sun Jan 21 04:08:59 GMT 2024 aarch64 GNU/Linux

1 Like

Is this something @MichaIng can make standard with DietPi ?