#!/usr/bin/env bash
# should be run from inside "fx" dir of ICS
# fd . -t f -x ffmpeg -i {} -filter:a volumedetect -f null /dev/null 2>&1 | rg 'mean_volume|max_volume'
# fd . -d 1 -t f -x ffmpeg -i {} -filter:a volumedetect -f null /dev/null 2>&1 | rg 'mean_volume' | cut -d ':' -f 2 | sed 's/^[^0123456789]*\([0-9].*\) dB/\1/' | awk '{SUM+=$1}END{print SUM}'
# make patch dir
patch_dir="../../../05 Immersive Combat Sounds - Replacement Patch/Sound/Fx/item"
temp_dir="../../../99_temp_dir/Sound/Fx/item"
if [ ! -d "${patch_dir}" ]; then mkdir -pv "${patch_dir}"; fi
if [ ! -d "${temp_dir}" ]; then mkdir -pv "${temp_dir}"; fi
# don't change it's volume
mv -v "body hit.wav" "${patch_dir}/bodyHit.wav"
# increase volume a bit more than others
mv -v "swoosh 1.wav" "${temp_dir}/swishW.wav"
mv -v "swoosh 2.wav" "${temp_dir}/swishS.wav"
mv -v "swoosh 3.wav" "${temp_dir}/swishL.wav"
fd . "${temp_dir}" -x ffmpeg -i "{}" -filter:a "volume=12dB" "${patch_dir}/{/}"
fd . "${temp_dir}" -x rm
# copy
cp -v "${patch_dir}/swishW.wav" "${patch_dir}/swishM.wav"
# rename other files that require renaming
mv -v "Light Armor Hit.wav" "${temp_dir}/armorhitL.wav"
mv -v "Heavy Armor Hit.wav" "${temp_dir}/armhitH.wav"
mv -v "Medium Armor Hit.wav" "${temp_dir}/armhitM.wav"
mv -v "item/cbowOUT.wav" "${temp_dir}/cbowOUT2.wav"
mv -v "item/cbowAWAY.wav" "${temp_dir}/cbowAWAY2.wav"
mv -v "item/bowSHOOT.wav" "${temp_dir}/bwshoot.wav" 
mv -v "item/cbowSHOOT.wav" "${temp_dir}/crbowSHOOT.wav"
# increase volume
fd . "${temp_dir}" -x ffmpeg -i "{}" -filter:a "volume=5dB" "${patch_dir}/{/}"
# now change volume for the rest files
fd . "item" -x ffmpeg -i "{}" -filter:a "volume=5dB" "${patch_dir}/{/}"
