Skip to content

Commit

Permalink
pipewire: create 2 virtual audio devices and add user config for them
Browse files Browse the repository at this point in the history
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 <[email protected]>

pipewire: enable virtual audio drivers for all rocknix devices

Signed-off-by: Paul Reioux <[email protected]>
  • Loading branch information
faux123 authored and sydarn committed Jun 12, 2024
1 parent 81ef945 commit 1d41280
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/audio/pipewire/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions packages/audio/pipewire/sources/audio-v-devs.conf
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
68 changes: 68 additions & 0 deletions packages/audio/pipewire/sources/audio_vdriver.sh
Original file line number Diff line number Diff line change
@@ -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 <stereo|mono>" >&2
exit 1
;;
esac

0 comments on commit 1d41280

Please sign in to comment.