Skip to content

Instantly share code, notes, and snippets.

@oxtoacart
Last active January 6, 2019 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxtoacart/236ec6ac4a31bd467d0db15f56134354 to your computer and use it in GitHub Desktop.
Save oxtoacart/236ec6ac4a31bd467d0db15f56134354 to your computer and use it in GitHub Desktop.
Apply advanced crossfeed using Redline Monitor
#!/bin/bash
# Set up parameters
in=`realpath "${1}"`
echo $in
indir="${in%/*}"
infile="${in##*/}"
outdir="${indir}_headphone"
tmpin="/tmp/in_${infile}.flac"
tmpout="/tmp/out_${infile}.flac"
out="crossfed_${infile}"
# Get the original bit depth for later
original_bit_depth=`file -b "${in}" | cut -d " " -f 5`
if [ "${original_bit_depth}" == "24" ]; then
sample_fmt="s32"
else
sample_fmt="s16"
fi
function remove_temp_files() {
rm "${tmpin}"
rm "${tmpout}"
}
function die() {
echo $*
remove_temp_files
exit 1
}
# Note - I'm using a bunch of temp files because I couldn't get streaming processing at high bit depths to work well with mrswatson64
# Reduce level to leave processing headroom for mrwatson
ffmpeg -loglevel quiet -y -i "${in}" -filter:a "volume=-6dB" -sample_fmt s32 "${tmpin}" || die "unable to reduce input level"
# Apply advanced crossfeed
SLIGHTLY_LESS_CENTER=0.333
SLIGHTLY_MORE_CENTER=0.667
MOST_CENTER=1
WIDE_SOUNDSTAGE=0.75 # 75% vs default of 60%
WIDEST_SOUNDSTAGE=1
mrswatson64 --quiet --bit-depth 24 -p /Library/Audio/Plug-Ins/VST/Redline\ Monitor.vst --parameter 0,${SLIGHTLY_MORE_CENTER} --parameter 1,${WIDE_SOUNDSTAGE} --input "${tmpin}" --output "${tmpout}" 2>&1|| die "unable to apply crossfeed"
# Normalize to 0dB peak to reduce the amount of amplification needed at playback
vol=`ffmpeg -i "${tmpout}" -af "volumedetect" -vn -sn -dn -f null /dev/null 2>&1 | grep "max_volume" | cut -d ' ' -f 5 | sed 's/\-//'` || die "unable to determine max volume"
# Note, I'm using the highest compression level to save space, but this slows down encoding
ffmpeg -loglevel quiet -y -i "${tmpout}" -filter:a "volume=+${vol}dB" "${out}" || die "unable to encode final output"
remove_temp_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment