#!/bin/bash # CLICK DETECT version 0.16, september 28, 2010, Pieter Suurmond. # Bash shell script that searches a given directory (recursively) for WAV files; # Converts them (temporarily) to AIFF files (with SOX) and calls the C-program # 'click_detect' for all of them, reporting possible clicks and glitches to the # standard output. # First print version number of this script: echo "CD click_detect_wav version 0.16, Pieter Suurmond, sept 28, 2010." # And print version number of the C sub-program: ./click_detect -v # Check whether we have 1 argument: echo "" if [ $# -ne 1 ] then echo "Please supply a (single) directory as argument!" exit fi # Filename of temporary textfile created in current directory: TMP_LIST=_tmp_click_detect_wavs.txt COUNT_FILES=0 COUNT_CLICKS=0 # Collect all WAV-filenames in a temporary textfile # (note that we can only run one script at a time!): echo "Scanning directory $1 ..." find $1 -iname "*.wav" > $TMP_LIST # Then put in alphabetic order (in-place conversion): sort $TMP_LIST -o $TMP_LIST # Then iterate over all names: cat $TMP_LIST | while read NAAM; do ((COUNT_FILES++)) # Extract the last component of the pathname and cut the trailing ".wav". # (${string##substring} = Strip longest match of $substring from front of $string) T="${NAAM##*/}" # (${string%substring} = Strip shortest match of $substring from back of $string) T="${T%.wav}" # Name of the temporary aiff file: TAIF=_tmp_"$T".aiff # Create temporary AIFF-file and search it for clicks / glitches / dropouts. sox "$NAAM" "$TAIF" ./click_detect "$TAIF" # Exit code of the last command is stored in '$?'. Report only errors. if (($?)) then ((COUNT_CLICKS++)) echo "$COUNT_CLICKS: (file $COUNT_FILES) CLICK in $NAAM!" echo " " # exit fi # Remove temporary AIFF-file. rm "$TAIF" done # Remove temporary textfile. rm $TMP_LIST echo "Done."