Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ ! $# -eq 4 ]
- then
- echo "Incorrect number of arguments:" $# "/ 4"
- exit
- fi
- error=0
- if [ ! -f $1 ]
- then
- echo "Log file" $1 "not found"
- error=1
- fi
- if [ ! -f $2 ]
- then
- echo "Eeg file" $2 "not found"
- error=1
- fi
- if [ ! -f $3 ]
- then
- echo "Audio file" $3 "not found"
- error=1
- fi
- if [ $error -eq 1 ]
- then
- echo "Errors encountered, goodbye"
- fi
- if [ ! -d $4 ]
- then
- mkdir -p $4 #create the output directory if it doesn't exist already
- fi
- if [ "${EEG_TZ}" == "" ]
- then
- EEG_TZ="UTF"
- fi
- eegDate=$(grep -E '^<StartRecordingDate>' "$2" | sed -E 's_.*>(.*)[.](.*)[.](.*)<.*_\3-\2-\1_')
- eegFullHour=$(grep -E '^<StartRecordingTime>' "$2" | sed -E 's_.*>(.*)<.*_\1_')
- if [ $eegDate = "" -o $eegFullHour = "" ]
- then
- echo "Eeg start not found, bye"
- fi
- eegS=$(echo $eegDate $eegFullHour)
- eegStart=$(date --date "$eegS" +%s.%N)
- hz=$(grep -E '^<SamplingRate>' $2 | grep -oE '[0-9]+')
- duplicates=$(grep -oE '^[^ ]+' timetable.log | sort | uniq -d)
- # TODO check if not empty
- wavStart=$(grep -E '^beep' $1 | grep -oE '[0-9.]+$')
- #TODO check if eeg/wav start is empty
- ticks=$(grep -E '^<tick>' $2)
- tickCount=$(echo "$ticks" | wc -l)
- echo "ticks = $tickCount"
- eegDuration=$(echo "$tickCount / $hz" | bc -l)
- eegEnd=$(echo "$eegStart + $eegDuration" | bc)
- wavDuration=$(sox $3 -n stat 2>&1 | grep '^Length' | sed -E 's_.*[[:space:]]([.0-9]+$)_\1_')
- wavEnd=$(echo "$wavStart + $wavDuration" | bc)
- echo "[file] [start] [end] [duration]"
- echo "eeg $eegStart $eegEnd $eegDuration"
- echo "wav $wavStart $wavEnd $wavDuration"
- st=$(cat $1)
- IFS=$'\n'
- for x in $st; do
- name=$(echo $x | grep -oE '^[^ ]+')
- # in case someone decides to put multiple spaces
- durationExpr=$(echo $x | sed -E 's_^.*[[:space:]]+([0-9.]+)[[:space:]]([0-9.]+)$_\2-\1_')
- # in unix time
- uStart=$(echo $durationExpr | cut -d'-' -f2)
- uEnd=$(echo $durationExpr | cut -d'-' -f1)
- duration=$(echo $durationExpr | bc | sed -E 's_^[.]_0._')
- #echo "Parsed $name $uStart $uEnd $duration"
- fail=$(echo "$duration < 0.2" | bc)
- if [ $fail -eq "1" ]
- then
- echo "Duration for $name is too short ($duration), you fucking PoS"
- fi
- audioStart=$(echo "$uStart-$wavStart" | bc)
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement