Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Last active January 7, 2023 13:11
Show Gist options
  • Save Sanix-Darker/06f80e8abddd6fe8b9f180a002c24f45 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/06f80e8abddd6fe8b9f180a002c24f45 to your computer and use it in GitHub Desktop.
#!/bin/bash
# this small scrip combine audio streams from a running instance of pulseaudio
# and creates a new virtual input
f_log() {
echo "[+] $0 -> $*"
}
function usage () {
cat << EOF
You need to call this script like this : $0 (-r) -i <input>
-r : reset pulseaudio to default and so removes virtual input
EOF
}
while getopts "hri:" option
do
case ${option} in
h)
usage
exit
;;
r)
action=reset
;;
i)
amplifier_model=${OPTARG}
;;
?)
usage
exit
;;
esac
done
# Checking first if we just need to reset pulseaudio
if [ "${action}" == "reset" ] ; then
f_log "Resetting pulseaudio to defaults ..."
pactl unload-module module-loopback
pactl unload-module module-null-sink
sleep 2
pulseaudio -k
exit
fi
# Parsing amplifier input to combine and exit if not specified
# One can use the following commands to know which sources are available
# pacmd list-sources | egrep '(^\s+name: .*)|(^\s+device.description = .*)'
f_log "Soundcore Life Q30"
source_device="alsa_input.usb-046d_BRIO_4K_Stream_Edition_1DB4692C-02.analog-stereo"
sink_name="monitor-soundCore"
fake_input_name="SoundCore-And-Mic"
# Now let's do the real work
# Common
monitor_device="bluez_sink.AC_12_2F_50_D9_56.a2dp_sink.monitor"
f_log "Adding new sink [${sink_name}]"
pactl load-module \
module-null-sink sink_name=${sink_name} \
sink_properties=device.description=Source-monitor-amp
sleep 5
f_log "Adding monitor device [${monitor_device}] to created sink [${sink_name}]"
pactl load-module \
module-loopback source=${monitor_device} \
sink_dont_move=true sink=${sink_name}
sleep 5
f_log "Adding external amplifier [${source_device}] to created sink [${sink_name}]"
pactl load-module \
module-loopback source=${source_device} \
sink_dont_move=true sink=${sink_name}
sleep 5
# Create fake input combining all sinks
f_log "Creating new virtual input [${fake_input_name}] to be used as input for recording"
pactl load-module \
module-remap-source source_name=${fake_input_name} \
master=${sink_name}.monitor \
source_properties=device.description=${fake_input_name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment