Skip to content

Instantly share code, notes, and snippets.

@lazerl0rd
Last active June 20, 2020 13:38
Show Gist options
  • Save lazerl0rd/0cda36828490430165e5f886f7620d35 to your computer and use it in GitHub Desktop.
Save lazerl0rd/0cda36828490430165e5f886f7620d35 to your computer and use it in GitHub Desktop.
A Shell Script To Automate https://github.com/jaakkopasanen/AutoEq even more.
#!/usr/bin/env bash
# A Shell Script To Automate AutoEq even more.
# Diab Neiroukh - 23/Feb/2020 (Licensed under the GNU GPLv3)
declare -a fidelityTypes=("Enhanced Fidelity" "Lower Fidelity" "Native Fidelity" "Standard Fidelity")
gitConfig="$PWD/.git/config"
pythonExe="$(which python3.7)"
exuent() {
sleep 3 && exit 1
}
if [ -f $gitConfig ]; then
if ! $(cat $gitConfig | grep -q AutoEq); then
echo "Please make sure you are in a AutoEq clone and the name of the repo is the same."
exuent
fi
else
echo "Please cd into the AutoEq git clone before starting this program."
exuent
fi
if [[ -z "$1" ]]; then
showPlot=true
else
case $1 in
"cli")
showPlot=false
;;
"gui")
showPlot=true
;;
*)
echo "Only a single argument is supported, and that is 'cli' or 'gui'. This determines whether or not to show the plot in a pop-up window. The default is for it to be shown."
exuent
;;
esac
fi
for fidelityType in "${fidelityTypes[@]}"; do
mkdir -p "$PWD/my_results/$fidelityType"
done
if [[ -z "$NAME" ]]; then
echo "Please enter the name of your headphones exactly as it is stated in the index:"
read NAME
fi
# Check if data for $NAME exists.
if ! $(find -name "$NAME" | grep -q data); then
echo "The directory for $NAME's CSV data could not be found."
exuent
fi
input="$(find -name "$NAME" | grep data)"
if [[ -z "$TARGET" ]]; then
echo "Please enter the name of the target compensation CSV:"
read TARGET
# Correct target without .csv file extension.
if ! $(echo $TARGET | grep -q ".csv"); then
TARGET=$TARGET".csv"
fi
fi
# Check if $TARGET exists.
if [ ! -f "$PWD/compensation/$TARGET" ]; then
echo "The target CSV '$TARGET' could not be found."
exuent
fi
if [[ -z "$FIDELITY" ]]; then
echo "I have split the fidelity into four sections; Enhanced, Lower, Native, and Standard Fidelity."
echo "Enhanced Fidelity is 24-bit at 48000Hz."
echo "Lower Fidelity is 16-bit at 44100Hz."
echo "Native Fidelity is the native maximum of your headphones."
echo "Standard Fidelity is 16-bit at 48000Hz."
echo "Please enter the fidelity you wish the profile to be in:"
read FIDELITY
fi
case "$FIDELITY" in
# Accept both "Enhanced Fidelity" and "Enhanced".
"${fidelityTypes[0]}"|"$(echo ${fidelityTypes[0]} | awk '{print $1;}')")
# Make sure it copies to the right folder, eventually.
FIDELITY="${fidelityTypes[0]}"
BITDEPTH=24
FREQ=48000
;;
"${fidelityTypes[1]}"|"$(echo ${fidelityTypes[1]} | awk '{print $1;}')")
FIDELITY="${fidelityTypes[1]}"
BITDEPTH=16
FREQ=44100
;;
"${fidelityTypes[2]}"|"$(echo ${fidelityTypes[2]} | awk '{print $1;}')")
FIDELITY="${fidelityTypes[2]}"
echo "Unfortunately, there's no way for me to detect your headphone's native fidelity."
echo "Enter your headphone's bitdepth:"
read BITDEPTH
# Correct values like "24 bit".
BITDEPTH="$(echo $BITDEPTH | awk '{print $1;}')"
# Correct values containing "bit".
if $(echo $BITDEPTH | grep -q "bit"); then
if $(echo $BITDEPTH | grep -q "\-bit"); then
# Correct values like "24-bit".
BITDEPTH="${BITDEPTH//-bit}"
else
# Correct values like "24bit".
BITDEPTH="${BITDEPTH//bit}"
fi
fi
echo "Enter your headphone's native frequency in Hz:"
read FREQ
# Correct values like "14000 Hz".
FREQ="$(echo $FREQ | awk '{print $1;}')"
# Correct values like "14000Hz".
if $(echo $FREQ | grep -q "Hz"); then
FREQ="${FREQ//Hz}"
fi
;;
"${fidelityTypes[3]}"|"$(echo ${fidelityTypes[3]} | awk '{print $1;}')")
FIDELITY="${fidelityTypes[3]}"
BITDEPTH=16
FREQ=48000
;;
*)
echo "Please enter one of the four defined fidelity types."
exuent
;;
esac
# change this to check if venv dir exists
if false; then
virtualenv --python=$pythonExe venv
fi
# check if shell is bash here
source venv/bin/activate
if [ $showPlot = true ]; then
python autoeq.py --input_dir="$input" --fs "$FREQ" --bit_depth "$BITDEPTH" --output_dir="my_results/$FIDELITY/$NAME" --compensation="compensation/$TARGET" --equalize --parametric_eq --ten_band_eq --show_plot
else
python autoeq.py --input_dir="$input" --fs "$FREQ" --bit_depth "$BITDEPTH" --output_dir="my_results/$FIDELITY/$NAME" --compensation="compensation/$TARGET" --equalize --parametric_eq --ten_band_eq
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment