odinb / bash-plexamp-installer

PlexAmp-installer for Raspberry Pi with ARM64 HW. Headless music-player controlled from any other Plexamp client.
https://www.plex.tv/plexamp/
GNU General Public License v3.0
91 stars 8 forks source link

Alternate method for HDMI audio on RPi5 #29

Open bhcompy opened 1 week ago

bhcompy commented 1 week ago

I ran the script and couldn't get HDMI audio to work with either of the methods found in here or on the Plex forums (pulseaudio user service or setting dtoverlay=vc4-fkms-v3d and adding hdmi_drive=2 etc to config.txt). Couldn't even detect a sound card (aplay -l returned no sound cards, and rapsi-config showed none, either). Found some info stating that fkms is being deprecated and it sounds like some support was dropped from firmware in the RPi5, so I guess it makes sense. The solution I found was to use dtoverlay=vc4-kms-v3d and dtparam=audio=on instead in config.txt, the following line to /boot/firmware/cmdline.txt, reboot, and select the card in rapsi-config:

snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_compat_alsa=0

As far as the output, Plex sends it all as directplay and my receiver says it's receiving 7.1 (which is the max supported channels) but despite not showing it explicitly, it outputs whatever the source file is (so a 2ch/stereo track plays on the proper channels and a 6ch/5.1 surround track plays on the proper channels), and it picks up the proper sample rate and bitdepth.

n00b001 commented 6 days ago

Thanks for the fix - I've just encountered this issue myself.

A week later I encountered this issue again (I did a apt full-upgrade and enabled overlayfs - "dtoverlay=vc4-kms-v3d" was reverted to "dtoverlay=vc4-fkms-v3d")

odinb commented 6 days ago

I ran the script and couldn't get HDMI audio to work with either of the methods found in here or on the Plex forums (pulseaudio user service or setting dtoverlay=vc4-fkms-v3d and adding hdmi_drive=2 etc to config.txt). Couldn't even detect a sound card (aplay -l returned no sound cards, and rapsi-config showed none, either). Found some info stating that fkms is being deprecated and it sounds like some support was dropped from firmware in the RPi5, so I guess it makes sense. The solution I found was to use dtoverlay=vc4-kms-v3d and dtparam=audio=on instead in config.txt, the following line to /boot/firmware/cmdline.txt, reboot, and select the card in rapsi-config:

snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_compat_alsa=0

As far as the output, Plex sends it all as directplay and my receiver says it's receiving 7.1 (which is the max supported channels) but despite not showing it explicitly, it outputs whatever the source file is (so a 2ch/stereo track plays on the proper channels and a 6ch/5.1 surround track plays on the proper channels), and it picks up the proper sample rate and bitdepth.

Since I am not using HDMI, but rather an audio-card, can you send me the references for this change? Also, please send me the exact changes you needed to do and the files they were done in. Is this change valid for RPi5 only, or all RPis? If all, I will see if I can fix the script, if not, it will be a comment in the wiki for now.

n00b001 commented 6 days ago

I recently migrated from a rpi4 to rpi5 - I have previously not had this issue with rpi4.

bhcompy commented 5 days ago

Since I am not using HDMI, but rather an audio-card, can you send me the references for this change?

Commands to add to cmdline.txt (poster is tagged as an RPi engineer and is a moderator on the official forums)

Same engineer saying fkms is deprecated on RPi5

Regarding prior to RPi5, this is a post about the CM4 device, which is the same underlying hardware as the RPi4 suggesting the move, though it sounds like the commands technically still work

Additionally, due to how my receiver works, I saved my edid and added force_hotplug to the cmdline.txt so that if my RPI booted up when the receiver was off, it would still pick up the receiver (otherwise it would require a reboot as the hdmi port on the receiver doesn't respond in standby, so the port responds as if it's unplugged). This may not be necessary for everyone, but seems to be with Onkyo.

Because of how Github comments work, I'll note the changes and then paste the full text of the file:

end of line 1: drm.edid_firmware=myedid.dat vc4.force_hotplug=1 add another line: snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_compat_alsa=0

My /boot/firmware/cmdline.txt: console=serial0,115200 console=tty1 root=PARTUUID=ecdc4b09-02 rootfstype=ext4 fsck.repair=yes rootwait cfg80211.ieee80211_regdom=GB drm.edid_firmware=myedid.dat vc4.force_hotplug=1 snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_compat_alsa=0

Creating the custom edid: sudo cp /sys/devices/platform/axi/axi:gpu/drm/card1/card1-HDMI-A-1/edid /lib/firmware/myedid.dat

This is by port. A different edid may need to be created if using the using the other port or using both ports. For troubleshooting or to see ports/validate they're detected: sudo find /sys/ -name edid

Expected output (it's blank by default if nothing is detected): /sys/devices/platform/axi/axi:gpu/drm/card1/card1-HDMI-A-1/edid /sys/devices/platform/axi/axi:gpu/drm/card1/card1-Writeback-1/edid /sys/devices/platform/axi/axi:gpu/drm/card1/card1-HDMI-A-2/edid /sys/devices/platform/axi/axi:gpu/drm/card1/card1-Writeback-2/edid

Examine edid: cat /sys/class/drm/card?-HDMI-A-1/edid|parse-edid

My /boot/firmware/config.txt: \# For more options and information see \# http://rptl.io/configtxt \# Some settings may impact device functionality. See link above for details

\# Uncomment some or all of these to enable the optional hardware interfaces \#dtparam=i2c_arm=on \#dtparam=i2s=on \#dtparam=spi=on

\# Enable audio (loads snd_bcm2835) dtparam=audio=on

\# Additional overlays and parameters are documented \# /boot/firmware/overlays/README

\# Automatically load overlays for detected cameras camera_auto_detect=1

\# Automatically load overlays for detected DSI displays display_auto_detect=1

\# Automatically load initramfs files, if found auto_initramfs=1

\# Enable DRM VC4 V3D driver dtoverlay=vc4-kms-v3d max_framebuffers=2

\# Don't have the firmware create an initial video= setting in cmdline.txt. \# Use the kernel's default instead. disable_fw_kms_setup=1

\# Run in 64-bit mode arm_64bit=1

\# Disable compensation for displays with overscan disable_overscan=1

\# Run as fast as firmware / board allows arm_boost=1

[cm4] \# Enable host mode on the 2711 built-in XHCI USB controller. \# This line should be removed if the legacy DWC2 controller is required \# (e.g. for USB device mode) or if USB support is not required. otg_mode=1

[cm5] dtoverlay=dwc2,dr_mode=host

[all]

Github apparently doesn't allow you to escape out poundsigns in code quotes (what the hell github?), so remove the \ from the \#

odinb commented 4 days ago

Thanks for the additional input! Updated the script, and changed all instances of "fkms" to "kms". This should hopefully fix the issue, if not please let me know and what the issue/fix was/is!

Please keep in mind, this script is aimed at headless primarily, so if conflicts, the headless config will win.

Will leave the ticket open for about a week for you to reply, then I will close if nothing more is found.

bhcompy commented 4 days ago

By all instances you mean on RPi5? Or on every device? I think fkms works on older devices (though maybe not preferred on the most recent OS, but it's not clear if these settings work on older RPi's as I do not have access to any to test)

odinb commented 4 days ago

@bhcompy: Basically on any device! I tested on my RPi4, and it still worked after re-configuring the Audio-card. Did not try fresh install. Found this info, will put it in the wiki:

Here's what we know at time of writing about KMS (Kernel Mode Setting) and FKMS (Fake Kernel Mode Setting) on Raspberry Pi:

KMS vs FKMS KMS (Kernel Mode Setting):

FKMS (Fake Kernel Mode Setting):

Recommendations For Raspberry Pi 4 or later:

For older Raspberry Pi models:

Important Considerations

  1. KMS on Pi affects more than just mode setting - it also configures 2D compositing planes through the DRM (Direct Render Manager) subsystem.

  2. Switching between KMS and FKMS may require additional configuration changes:

    • Modifying boot/config.txt
    • Potentially adjusting hdmi_mode and group_mode parameters
    • Possibly editing /boot/cmdline.txt
  3. The choice between KMS and FKMS can impact performance and compatibility with certain features or software.

  4. If using the official Raspberry Pi 7" Touchscreen, additional overlays may be needed for KMS: dtoverlay=vc4-kms-dsi-7inch dtoverlay=rpi-ft5406

  5. For the most up-to-date and model-specific recommendations, it's best to consult the official Raspberry Pi documentation or forums, as the preferred options can change with software updates.

bhcompy commented 4 days ago

Oh fantastic. Hopefully it works for everyone

bhcompy commented 3 days ago

Please keep in mind, this script is aimed at headless primarily, so if conflicts, the headless config will win.

I just wanted to clarify, the hdmi approach is still headless (video output is just the CLI, so it's useless), but it doesn't require purchasing a HAT (save $$) and it doesn't have the limitations of optical/spdif/rca (which are fine for 2ch audio, but have limitations for 6ch+ audio)