Want to support development? Maybe get a nice server to do your own development on? Check out BuyVM or Vultr using our affiliate links! New users get $50 of free credit with Vultr, and BuyVM offers affordable servers with affordable, true DDoS filtering. You can also support us on Patreon.
Description: CLI Loudness Script
Submitted on November 10, 2019 at 07:14 PM

album-ebur128 (Bash)

#!/bin/bash
# Script to calculate audio track and album loudness values
# Christopher Hampson 11/02/2019

function calc # calculate whole album values
{
	ALBUM_INT=`cat $ALBUMLUFS_VALUES | awk '{if(NR==1) print $3}'`
	ALBUM_LRA=`cat $ALBUMLUFS_VALUES | awk '{if(NR==2) print $3}'`
	ALBUM_TP=`cat $ALBUMLUFS_VALUES | awk '{if(NR==3) print $3}'`
	ALBUM_MM=`cat $ALBUMLUFS_VALUES | awk '{if(NR==8) print $3}'`
	ALBUM_STM=`cat $ALBUMLUFS_VALUES | awk '{if(NR==9) print $4}'`
}
LUFS_HEADER=$(mktemp)
FILENAME=$(mktemp)
LUFS_VALUES=$(mktemp)
ALBUMLUFS_VALUES=$(mktemp)
SCREEN=$(mktemp)
ANALYSIS=$(mktemp)

sox "[email protected]" -t wav - | ebur128 --lufs --full - >> $ALBUMLUFS_VALUES &

date > $LUFS_HEADER
echo "LOUDNESS ANALYSIS" >> $LUFS_HEADER
echo "File,Int (LUFS),LRA (LU) ,TP (dB)" >> $LUFS_HEADER
for file in "[email protected]";
do
	echo `basename "$file"` >> $FILENAME
	echo -n "," >> $LUFS_VALUES
	ebur128 --lufs "$file" | tee $SCREEN | awk '{print $3}' | tr "\n" "," | sed 's/\(.*\),/\1/' >> $LUFS_VALUES
	echo >> $LUFS_VALUES
	echo
	echo "$file"
	echo
	cat $SCREEN	&
done
wait
sed -i 's/,//g' $FILENAME
paste -d "" $FILENAME $LUFS_VALUES > $ANALYSIS
cat $ANALYSIS >> $LUFS_HEADER

calc # calculates the whole album data

echo
echo "ALBUM:"
echo "Integrated loudness:" $ALBUM_INT "LUFS"
echo "Loudness range:" $ALBUM_LRA "LU"
echo "Peak level:" $ALBUM_TP "dB"
echo "Momentary max:" $ALBUM_MM "LUFS"
echo "Short term max:" $ALBUM_STM "LUFS"


cat > loudness_analysis.html <<'EOF'
<head>
<style>

td, th {
border: 1px solid #999;
padding: 0.5rem;
}

</style>
</head>
<table>
EOF
while read INPUT ; do echo "<tr><td>${INPUT//,/</td><td>}</td></tr>"; done < $LUFS_HEADER  >> loudness_analysis.html
echo "<tr></tr>" >> loudness_analysis.html
echo "<tr><td><b>ALBUM</b></td><td><b>"$ALBUM_INT"</b></td><td><b>"$ALBUM_LRA"</b></td><td><b>"$ALBUM_TP"</b></td></tr>" >> loudness_analysis.html
echo "<tr><td><b>M<sub>MAX</sub></td><td><b>"$ALBUM_MM"</b></td></tr>" >> loudness_analysis.html
echo "<tr><td><b>S<sub>MAX</sub></td><td><b>"$ALBUM_STM"</b></td></tr>" >> loudness_analysis.html
echo "</table>" >> loudness_analysis.html
echo "<br>" >> loudness_analysis.html

rm $LUFS_HEADER $FILENAME $LUFS_VALUES $ALBUMLUFS_VALUES $SCREEN $ANALYSIS