Skip to content

Commit

Permalink
Merge pull request #23 from amiaopensource/noise-floor-fix
Browse files Browse the repository at this point in the history
more fixes
  • Loading branch information
dericed authored Apr 25, 2023
2 parents dd3ba09 + b1af406 commit c96a5ba
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions astataudit
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ _add_column(){
SECTION="${2}"
KEY="${3}"
VALUE="${4}"
if [[ "${FULL_DATA}" = "n" && "${IF_FULL}" = "n" ]] ; then
if [[ "${IF_FULL}" = "n" || ( "${FULL_DATA}" = "y" && "${IF_FULL}" = "y" ) ]] ; then
if [[ "${FILE_NUMBER}" = "0" ]] ; then
if [[ -n "${RELABEL}" ]] ; then
CSV_HEADER+="${RELABEL},"
Expand Down Expand Up @@ -154,6 +154,9 @@ _add_column(){
fi
CSV_ROW+="${CSV_VALUE},"
fi
if [[ "$KEY" == "File/Core/IMED" ]] ; then
echo "${CSV_VALUE}|${FILENAME}" >> "${DUP_CHECK_TMP}"
fi
}

_check_dependencies(){
Expand Down Expand Up @@ -324,13 +327,17 @@ _ss_to_hhmmss(){
esac
done
shift "$((OPTIND-1))"
INT="${1%.*}"
[[ -z "$INT" ]] && INT="0"
DEC="$(echo "${1#*.}" | head -c 3)"
if [[ "${NO_SLASH}" == "Y" ]] ; then
printf "%02d:%02d:%02d.${DEC}\n" $(($INT/3600)) $(($INT%3600/60)) $(($INT%60))
if [[ "${1}" == "n/a" ]] ; then
echo "${1}"
else
printf "%02d\:%02d\:%02d.${DEC}\n" $(($INT/3600)) $(($INT%3600/60)) $(($INT%60))
INT="${1%.*}"
[[ -z "$INT" ]] && INT="0"
DEC="$(echo "${1#*.}" | head -c 3)"
if [[ "${NO_SLASH}" == "Y" ]] ; then
printf "%02d:%02d:%02d.${DEC}\n" $(($INT/3600)) $(($INT%3600/60)) $(($INT%60))
else
printf "%02d\:%02d\:%02d.${DEC}\n" $(($INT/3600)) $(($INT%3600/60)) $(($INT%60))
fi
fi
}

Expand Down Expand Up @@ -371,13 +378,23 @@ _get_csv_row(){
}

#local math
RMS_level_ch_offset="$(_get_astats_2channel_offset "RMS level dB")"
dynamic_range_ch_offset="$(_get_astats_2channel_offset "Dynamic range")"
noise_floor_db_ch_offset="$(_get_astats_2channel_offset "Noise floor dB")"
noise_floor_count_ch_offset="$(_get_astats_2channel_offset "Noise floor count")"
NOISE_FLOOR_1_DURATION="$(echo "scale=3; ${SAMPLES_PER_ASTATS_CSV} * $(_astats_parse "${FILTER_REPORT}" "1" "Noise floor count")/ ${SAMPLE_RATE}" | bc)"
NOISE_FLOOR_2_DURATION="$(echo "scale=3; ${SAMPLES_PER_ASTATS_CSV} * $(_astats_parse "${FILTER_REPORT}" "2" "Noise floor count")/ ${SAMPLE_RATE}" | bc)"
noise_floor_duration_ch_offset="$(echo "scale=3; ${NOISE_FLOOR_1_DURATION} - ${NOISE_FLOOR_2_DURATION}" | bc)"
if [[ "${CHANNEL_COUNT}" -gt 1 ]] ; then
RMS_level_ch_offset="$(_get_astats_2channel_offset "RMS level dB")"
dynamic_range_ch_offset="$(_get_astats_2channel_offset "Dynamic range")"
noise_floor_db_ch_offset="$(_get_astats_2channel_offset "Noise floor dB")"
noise_floor_count_ch_offset="$(_get_astats_2channel_offset "Noise floor count")"
NOISE_FLOOR_1_DURATION="$(echo "scale=3; ${SAMPLES_PER_ASTATS_CSV} * $(_astats_parse "${FILTER_REPORT}" "1" "Noise floor count")/ ${SAMPLE_RATE}" | bc)"
NOISE_FLOOR_2_DURATION="$(echo "scale=3; ${SAMPLES_PER_ASTATS_CSV} * $(_astats_parse "${FILTER_REPORT}" "2" "Noise floor count")/ ${SAMPLE_RATE}" | bc)"
noise_floor_duration_ch_offset="$(echo "scale=3; ${NOISE_FLOOR_1_DURATION} - ${NOISE_FLOOR_2_DURATION}" | bc)"
else
RMS_level_ch_offset="n/a"
dynamic_range_ch_offset="n/a"
noise_floor_db_ch_offset="n/a"
noise_floor_count_ch_offset="n/a"
NOISE_FLOOR_1_DURATION="n/a"
NOISE_FLOOR_2_DURATION="n/a"
noise_floor_duration_ch_offset="n/a"
fi

# the following _add_column functions use the following arguments
# 1: 'astats to read from FILTER_REPORT
Expand Down Expand Up @@ -637,7 +654,7 @@ _make_graph(){
`#peak/rms left`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Channel 1 Level, -144 to 0 dBFS, Blue=peak, Yellow=RMS'[peakLH];
`#peak/rms right`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Channel 2 Level, -144 to 0 dBFS, Purple=peak, Yellow=RMS'[peakRH];
`#min/max`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Audio Min/Max Level -1...1. Blue=channel 1, Purple=channel 2.'[minmaxH];
`#zero crossing rate`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Ratio of Zero Crossing Count to Sample Rate. Blue=channel 1, Purple=channel 2.'[zeroH];
`#zero crossing rate`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Ratio of Zero Crossing Count to Sample Rate, 0 - 1. Blue=channel 1, Purple=channel 2.'[zeroH];
`#phase`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Correlation, -1 to 1'[phaseH];
`#dc offset`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='DC Offset, -0.01 to 0.01 dBFS offset in the mean displacement from 0'[dcoffH];
[j]${AUDIOFORMAT},astats=metadata=1:reset=1,asplit=4[astats1][astats2][astats3][astats4];
Expand Down Expand Up @@ -691,8 +708,9 @@ _make_graph(){
[top7]vstack=20,drawgrid=thickness=1:color=gray@0.5:width=iw/${VERTICAL_MARKINGS},drawgrid=thickness=1:color=${BORDER_COLOR}@0.2:width=(iw/${VERTICAL_MARKINGS})/10[graph];
color=c=${BORDER_COLOR}:s=${PAD_W}x${HEADER_HEIGHT_BIG}[HeaderG];
color=c=${BORDER_COLOR}:s=${PAD_W}x${HEADER_HEIGHT},split=13[top1G][top2G][top3G][top4G][top5G][top6G][top7G][peakLHG][peakRHG][minmaxHG][zeroHG][phaseHG][dcoffHG];
`#0-0.1_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x${GRAPH_H},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0.050',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='0.025',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='0.075',drawgrid=thickness=1:color=black@0.2:height=ih/16,drawgrid=thickness=1:color=black@0.5:height=ih/4,drawgrid=thickness=1:color=black@0.8:height=ih/2[zero1G];
`#1-1_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x${GRAPH_H},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-0.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='+0.5',drawgrid=thickness=1:color=black@0.2:height=ih/16,drawgrid=thickness=1:color=black@0.5:height=ih/4,drawgrid=thickness=1:color=black@0.8:height=ih/2,split=3[minmax1G][phase1G][dcoff1G];
`#0-1_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x${GRAPH_H},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='0.25',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='0.75',drawgrid=thickness=1:color=black@0.2:height=ih/16,drawgrid=thickness=1:color=black@0.5:height=ih/4,drawgrid=thickness=1:color=black@0.8:height=ih/2[zero1G];
`#-1-1_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x${GRAPH_H},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-0.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='+0.5',drawgrid=thickness=1:color=black@0.2:height=ih/16,drawgrid=thickness=1:color=black@0.5:height=ih/4,drawgrid=thickness=1:color=black@0.8:height=ih/2,split=2[minmax1G][phase1G];
`#-0.01-0.01_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x${GRAPH_H},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-0.005',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='+0.005',drawgrid=thickness=1:color=black@0.2:height=ih/16,drawgrid=thickness=1:color=black@0.5:height=ih/4,drawgrid=thickness=1:color=black@0.8:height=ih/2[dcoff1G];
`#-144-0_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x${GRAPH_H},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='-72',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-108',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='-36',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.02:x=w*0.7:text='0',drawgrid=thickness=1:color=black@0.2:height=ih/16,drawgrid=thickness=1:color=black@0.5:height=ih/4,drawgrid=thickness=1:color=black@0.8:height=ih/2,split=2[peakL1G][peakR1G];
[HeaderG]
[top1G][peakLHG][peakL1G]
Expand Down Expand Up @@ -743,6 +761,7 @@ _process_file(){
BASENAME="$(basename "${FILENAME}")"
unset CSV_ROW
FILTER_TMP_XMLD="$(_maketemp)"
CHANNEL_COUNT="$(ffprobe -v 0 -i "${FILENAME}" -show_entries stream=channels -select_streams a:0 -of default=nk=1:nw=1)"
_report -d "Processing: ${BASENAME}"
if [[ "${CSV_SUMMARY_OUTPUT}" = "y" || "${XML_OUTPUT}" = "y" || "${GRAPH_OUTPUT}" = "y" ]] ; then
_get_metadata "${FILENAME}" "${FILTER_TMP_XMLD}"
Expand Down Expand Up @@ -801,6 +820,7 @@ if [[ -f "${INPUT}" && "${INPUT_EXT}" != "txt" ]] ; then
while [[ "${@}" != "" ]] ; do
INPUT="$1"
FILES_XML_TMP="$(_maketemp)"
DUP_CHECK_TMP="$(_maketemp)"
if [[ -n "${SET_OUTPUT_DIR}" ]] ; then
OUTPUT_XML="${SET_OUTPUT_DIR}/$(basename "${INPUT}").astatsaudit.xml"
else
Expand Down Expand Up @@ -836,6 +856,7 @@ elif [[ -d "${INPUT}" || ( -f "${INPUT}" && "${INPUT_EXT}" == "txt" ) ]] ; then
mkdir -p "${OUTPUT_DIR}"
fi
FILES_XML_TMP="$(_maketemp)"
DUP_CHECK_TMP="$(_maketemp)"
OUTPUT_XML="${OUTPUT_DIR}/astatsaudit_${NOW}.xml"
OUTPUT_CSV="${OUTPUT_DIR}/astatsaudit_${NOW}.csv"
echo "<files>" > "${FILES_XML_TMP}"
Expand Down Expand Up @@ -865,3 +886,10 @@ elif [[ -d "${INPUT}" || ( -f "${INPUT}" && "${INPUT_EXT}" == "txt" ) ]] ; then
_finish_xml "${FILES_XML_TMP}" > "${OUTPUT_XML}"
fi
fi
if [[ -f "${DUP_CHECK_TMP}" ]] ; then
DUP_IMED="$(sort -t '|' -k1 "${DUP_CHECK_TMP}" | awk -F'|' '$1 in first{print first[$1] $0; first[$1]=""; next} {first[$1]=$0 ORS}')"
if [[ "${DUP_IMED}" != "" ]] ; then
_report -w "Found some duplicate IMED values..."
echo "${DUP_IMED}"
fi
fi

0 comments on commit c96a5ba

Please sign in to comment.