From 1d41280b7cf63cb9d84bc3ca1ce7533e8e7cc238 Mon Sep 17 00:00:00 2001 From: Paul Reioux Date: Thu, 9 May 2024 08:15:07 -0700 Subject: [PATCH] pipewire: create 2 virtual audio devices and add user config for them added mono and stereo virtual audio devices, this will allow handhelds such as the PowKiddy SX20 and others with just 1 mono speaker to downmix all stereo output for the single mono speaker so for games with channel specific audios, you miss out any audio while playing. This is a software only solution which allows greater flexibility to allow future manipulations of audio without touching the original HW configurations also adding the shell scripts to swap between the virtual devices later during ES operations pipewire: make virtual audio optional only for RK3326 and RK3566 platforms Signed-off-by: Paul Reioux pipewire: enable virtual audio drivers for all rocknix devices Signed-off-by: Paul Reioux --- packages/audio/pipewire/package.mk | 6 ++ .../audio/pipewire/sources/audio-v-devs.conf | 32 +++++++++ .../audio/pipewire/sources/audio_vdriver.sh | 68 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 packages/audio/pipewire/sources/audio-v-devs.conf create mode 100644 packages/audio/pipewire/sources/audio_vdriver.sh diff --git a/packages/audio/pipewire/package.mk b/packages/audio/pipewire/package.mk index 270ce84826..bd86cec072 100644 --- a/packages/audio/pipewire/package.mk +++ b/packages/audio/pipewire/package.mk @@ -89,6 +89,12 @@ post_install() { mkdir -p ${INSTALL}/etc/alsa/conf.d ln -sf /usr/share/alsa/alsa.conf.d/50-pipewire.conf ${INSTALL}/etc/alsa/conf.d/50-pipewire.conf ln -sf /usr/share/alsa/alsa.conf.d/99-pipewire-default.conf ${INSTALL}/etc/alsa/conf.d/99-pipewire-default.conf + + mkdir -p ${INSTALL}/etc/pipewire/pipewire.conf.d/ + cp ${PKG_DIR}/sources/audio-v-devs.conf ${INSTALL}/etc/pipewire/pipewire.conf.d/ + cp ${PKG_DIR}/sources/audio_vdriver.sh ${INSTALL}/usr/bin/ + chmod 0755 ${INSTALL}/usr/bin/audio_vdriver.sh + enable_service pipewire.socket enable_service pipewire.service enable_service pipewire-pulse.socket diff --git a/packages/audio/pipewire/sources/audio-v-devs.conf b/packages/audio/pipewire/sources/audio-v-devs.conf new file mode 100644 index 0000000000..3b197d8410 --- /dev/null +++ b/packages/audio/pipewire/sources/audio-v-devs.conf @@ -0,0 +1,32 @@ +context.modules = [ + { name = libpipewire-module-loopback + args = { + node.description = "Stereo Playback Device" + capture.props = { + node.name = "stereo_output" + media.class = "Audio/Sink" + audio.position = [ FL FR ] + } + playback.props = { + node.name = "playback.stereo_output" + audio.position = [ FL FR ] + node.passive = true + } + } + } + { name = libpipewire-module-loopback + args = { + node.description = "Mono Playback Device" + capture.props = { + node.name = "mono_output" + media.class = "Audio/Sink" + audio.position = [ MONO ] + } + playback.props = { + node.name = "playback.mono_output" + audio.position = [ MONO ] + node.passive = true + } + } + } +] diff --git a/packages/audio/pipewire/sources/audio_vdriver.sh b/packages/audio/pipewire/sources/audio_vdriver.sh new file mode 100644 index 0000000000..136b2fb518 --- /dev/null +++ b/packages/audio/pipewire/sources/audio_vdriver.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +#load some built-in useful functions +. /etc/profile.d/001-functions + +AUDIO_V_DEVICE_SETTING_KEY="audio.v-driver" + +get_current_driver() { + CONFDRIVER=$(get_setting ${AUDIO_V_DEVICE_SETTING_KEY}) + + if [ -z ${CONFDRIVER} ]; then + CONFDRIVER="stereo" #default to stereo + set_setting ${AUDIO_V_DEVICE_SETTING_KEY} ${CONFDIRVER} + fi +} + +load_driver() { + DRIVER_TO_LOAD=$1 + case ${DRIVER_TO_LOAD} in + "stereo") + number=$(wpctl status | grep -m 1 "Stereo Playback Device" | grep -Eo '[0-9]+' | awk 'NR==1{print; exit}') + ;; + "mono") + number=$(wpctl status | grep -m 1 "Mono Playback Device" | grep -Eo '[0-9]+' | awk 'NR==1{print; exit}') + ;; + *) + exit 3 + ;; + esac + + # Check if the number is extracted successfully + if [ -n "$number" ]; then + # Set the default with the extracted number + wpctl set-default "$number" + echo "Default set to $number" + else + echo "Error: Unable to extract number from command output." + fi +} + +case "$1" in + "--options") + echo "stereo mono" + ;; + "--start") + get_current_driver + load_driver ${CONFDRIVER} + ;; + "stereo" | "mono") + set_setting ${AUDIO_V_DEVICE_SETTING_KEY} $1 + get_current_driver + echo ${CONFDRIVER} + load_driver ${CONFDRIVER} + ;; + "") + get_current_driver + echo ${CONFDRIVER} + ;; + *) + echo "Unexpected parameter $1" >&2 + echo "Usage:" >&2 + echo " List available drivers: $0 --options" >&2 + echo " Load configured driver and set libs: $0 --start" >&2 + echo " Get current driver: $0" >&2 + echo " Configure driver to load immediately: $0 " >&2 + exit 1 + ;; +esac