Commit d3d4934a authored by Philipp's avatar Philipp

improved performance, tweaked thresholds

parent b1d80fa3
#!/bin/sh
##
## RMSMonitor v0.1
## RMSMonitor v0.1.1
##
## This script uses ffmpeg to monitor the RMS levels of internet radio
## livestreams and generates warnings when too low or too high.
......@@ -33,7 +33,7 @@ url="http://radio.koennmer.net/evosonic.mp3"
threslo=-40
# Upper threshold (must be negative integer or 0)
threshi=0
threshi=-2
# Lower threshold for 10 sec average (must be negative integer)
thresavglo=-60
......@@ -198,10 +198,10 @@ colorize() {
fi
colmax="$colok"
if [ $max -ge $(((threshi-1)*100/50)) ]
if [ $max -ge $((threshi*100/50)) ]
then
colmax="$coldanger"
elif [ $max -ge $(((threshi-1)*100/25)) ]
elif [ $max -ge $((threshi*100/25)) ]
then
colmax="$colwarning"
elif [ $max -le $((threslo*95/100)) ]
......@@ -213,10 +213,10 @@ colorize() {
fi
colmin="$colok"
if [ $min -ge $(((threshi-1)*100/15)) ]
if [ $min -ge $((threshi*100/50)) ]
then
colmin="$coldanger"
elif [ $min -ge $(((threshi-1)*100/10)) ]
elif [ $min -ge $((threshi*100/25)) ]
then
colmin="$colwarning"
elif [ $min -le $(((threslo*95/100)*4)) ]
......@@ -291,7 +291,6 @@ check() {
fi
d="$(date +%H:%M:%S)"
value=$(echo $line |cut -d'.' -f1)
line="$(printf '%11.6f' "$line")"
if [ "$value" = "-inf" ]
then
value="-10"
......@@ -309,11 +308,54 @@ check() {
if [ $c -ge 111 ]
then
avg=$(printf '%4d' "$((a/111))")
if [ "$stdoutenabled" = "1" ]
then
colorize
echo -n "\e[0m $d min: ${colmin}$( printf '%4d' $min ) \e[0m/ max: ${colmax}$( printf '%4d' $max ) \e[0m/ avg: ${colavg}$( printf '%4d' $avg )\e[0m\r"
fi
if [ ${avg} -le ${thresavglo} ]
then
avglo=$((lo+1))
avglook=0
elif [ ${avg} -gt ${thresavglo} ]
then
avglook=$((look+1))
fi
if [ ${avg} -ge ${thresavghi} ]
then
avghi=$((hi+1))
avghiok=0
else
avghiok=$((avghiok+1))
fi
if [ $avghiok -eq 66 ]
then
if [ $avghi -ge 6 ]
then
warning "ok" "avg" "$avg"
fi
avghi=0
fi
if [ $avglook -eq 6 ]
then
if [ $avglo -ge 333 ]
then
warning "ok" "avg" "$avg"
fi
avglo=0
fi
if [ $avghi -eq 6 ] && [ $avghiok -eq 0 ]
then
warning "hi" "avg" "$max"
elif [ $avglo -eq 333 ] && [ $avglook -eq 0 ]
then
warning "lo" "avg" "$avg"
fi
if [ $min -eq 0 ]
then
min=-2
......@@ -350,22 +392,6 @@ check() {
hiok=$((hiok+1))
fi
if [ ${avg} -le ${thresavglo} ]
then
avglo=$((lo+1))
avglook=0
elif [ ${avg} -gt ${thresavglo} ]
then
avglook=$((look+1))
fi
if [ ${avg} -ge ${thresavghi} ]
then
avghi=$((hi+1))
avghiok=0
else
avghiok=$((avghiok+1))
fi
if [ $hiok -eq 66 ]
then
if [ $hi -ge 6 ]
......@@ -383,35 +409,12 @@ check() {
lo=0
fi
if [ $avghiok -eq 66 ]
then
if [ $avghi -ge 6 ]
then
warning "ok" "avg" "$avg"
fi
avghi=0
fi
if [ $avglook -eq 6 ]
then
if [ $avglo -ge 333 ]
then
warning "ok" "avg" "$avg"
fi
avglo=0
fi
if [ $hi -eq 6 ] && [ $hiok -eq 0 ]
then
warning "hi" "peak" "$max"
elif [ $lo -eq 333 ] && [ $look -eq 0 ]
then
warning "lo" "peak" "$min"
elif [ $avghi -eq 6 ] && [ $avghiok -eq 0 ]
then
warning "hi" "avg" "$max"
elif [ $avglo -eq 333 ] && [ $avglook -eq 0 ]
then
warning "lo" "avg" "$avg"
fi
done
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment