1
0
mirror of https://github.com/AquaMorph/dotfiles.git synced 2025-05-22 01:36:59 +00:00

Audio interface mixing scripts

This commit is contained in:
Christian Colglazier 2020-10-10 21:16:33 -04:00
parent 87054f8ca1
commit d28568ee03
2 changed files with 197 additions and 0 deletions

89
scripts/aquamix.sh Normal file

@ -0,0 +1,89 @@
#!/bin/bash
# Script to manuage audio mixing the the main audio interface.
# Import library
source $(dirname ${BASH_SOURCE[0]})/audio-lib.sh
INTERFACE_NAME='Scarlett 18i20'
INTERFACE_NUM=$(getCardNumber $INTERFACE_NAME)
# Sets the volume levels of the first mono instrument.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setMonoOne() {
setMono $INTERFACE_NUM 1 $1 $2 $3
}
# Sets the volume levels of the second mono instrument.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setMonoTwo() {
setMono $INTERFACE_NUM 2 $1 $2 $3
}
# Sets the volume levels of the third mono instrument.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setMonoThree() {
setMono $INTERFACE_NUM 3 $1 $2 $3
}
# Sets the volume levels of the first stereo instrument.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setStereoOne() {
setStereo $INTERFACE_NUM 5 $1 $2 $3
}
# Sets the volume levels of the second stereo instrument.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setStereoTwo() {
setStereo $INTERFACE_NUM 7 $1 $2 $3
}
# Sets the volume levels of the studio microphone.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setMic() {
setMono $INTERFACE_NUM 4 $1 $2 $3
}
# Sets the volume levels of the computer.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setComputerAudio() {
setStereo $INTERFACE_NUM 17 $1 $2 $3
}
# Sets the volume levels of all instrument.
#
# $1 monitor volume
# $2 first headphone volume
# $3 second headphone volume
function setInstruments() {
setMonoOne $1 $2 $3
setMonoTwo $1 $2 $3
setMonoThree $1 $2 $3
setStereoOne $1 $2 $3
setStereoTwo $1 $2 $3
}
setInstruments $ZERO_DB
setMic $MUTE
setComputerAudio $ZERO_DB

108
scripts/audio-lib.sh Normal file

@ -0,0 +1,108 @@
# Mix names
MONITOR_LEFT='A'
MONITOR_RIGHT='B'
HEADPHONE_01_LEFT='C'
HEADPHONE_01_RIGHT='D'
HEADPHONE_02_LEFT='E'
HEADPHONE_02_RIGHT='F'
BLANK_LEFT="G"
BLANK_RIGHT='H'
# Level constants
MUTE='0'
ZERO_DB='0db'
# Formats a number to match the matrix numbering.
function formatMatrixNum() {
printf "%02d" $1
}
# Returns audio card number with matching card name.
function getCardNumber() {
echo $(cat /proc/asound/cards | grep -m 1 $1 | grep -Po '\d{1,2}' | head -1)
}
# Prints a list of all controls for the given sound card.
function printControls() {
amixer -c $1 controls
}
# Sets a mix to a level.
#
# $1 card number
# $2 matrix number
# $3 mix channel
function setMix() {
amixer -c $1 set "Matrix $(formatMatrixNum $2) Mix $3" $4
}
# Sets the volume levels for a mono mix.
#
# $1 card number
# $2 matrix number
# $3 mix left channel
# $4 mix right channel
# $5 volume
function setMonoMix() {
setMix $1 $2 $3 $5
setMix $1 $2 $4 $5
}
# Sets the volume levels for a stereo mix.
#
# $1 card number
# $2 matrix number
# $3 mix left channel
# $4 mix right channel
# $5 volume
function setStereoMix() {
matrix=$2
setMix $1 $matrix $3 $5
setMix $1 $matrix $4 $MUTE
setMix $1 $((matrix+1)) $3 $MUTE
setMix $1 $((matrix+1)) $4 $5
}
# Sets the volume levels for a mono mix for several outputs.
#
# $1 card number
# $2 matrix number
# $3 mix left channel
# $4 mix right channel
# $5 monitor volume
# $6 first headphone volume
# $7 second headphone volume
function setMono() {
monitor=$3
headphone1=$4
headphone2=$5
if [ -n $headphone1 ]; then headphone1=$monitor; fi
if [ -n $headphone2 ]; then headphone2=$monitor; fi
setMonoMix $1 $2 $MONITOR_LEFT $MONITOR_RIGHT $monitor
setMonoMix $1 $2 $HEADPHONE_01_LEFT $HEADPHONE_01_RIGHT $headphone1
setMonoMix $1 $2 $HEADPHONE_02_LEFT $HEADPHONE_02_RIGHT $headphone2
setMonoMix $1 $2 $BLANK_LEFT $BLANK_RIGHT $MUTE
}
# Sets the volume levels for a stereo mix for several outputs.
#
# $1 card number
# $2 matrix number
# $3 mix left channel
# $4 mix right channel
# $5 monitor volume
# $6 first headphone volume
# $7 second headphone volume
function setStereo() {
monitor=$3
headphone1=$4
headphone2=$5
if [ -n $headphone1 ]; then headphone1=$monitor; fi
if [ -n $headphone2 ]; then headphone2=$monitor; fi
setStereoMix $1 $2 $MONITOR_LEFT $MONITOR_RIGHT $monitor
setStereoMix $1 $2 $HEADPHONE_01_LEFT $HEADPHONE_01_RIGHT $headphone1
setStereoMix $1 $2 $HEADPHONE_02_LEFT $HEADPHONE_02_RIGHT $headphone2
setStereoMix $1 $2 $BLANK_LEFT $BLANK_RIGHT $MUTE
}