SHARE
TWEET

Untitled

a guest Apr 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. if [ ! $# -eq 4 ]
  4. then
  5.     echo "Incorrect number of arguments:" $# "/ 4"
  6.     exit
  7. fi
  8.  
  9. error=0
  10.  
  11. if [ ! -f $1 ]
  12. then
  13.     echo "Log file" $1 "not found"
  14.     error=1
  15. fi
  16.  
  17. if [ ! -f $2 ]
  18. then
  19.     echo "Eeg file" $2 "not found"
  20.     error=1
  21. fi
  22.  
  23. if [ ! -f $3 ]
  24. then
  25.     echo "Audio file" $3 "not found"
  26.     error=1
  27. fi
  28.  
  29. if [ $error -eq 1 ]
  30. then
  31.     echo "Errors encountered, goodbye"
  32. fi
  33.  
  34.  
  35. if [ ! -d $4 ]
  36. then
  37.         mkdir -p $4 #create the output directory if it doesn't exist already
  38. fi
  39.  
  40. if [ "${EEG_TZ}" == "" ]
  41. then
  42.     EEG_TZ="UTF"
  43. fi
  44.  
  45. eegDate=$(grep -E '^<StartRecordingDate>' "$2" | sed -E 's_.*>(.*)[.](.*)[.](.*)<.*_\3-\2-\1_')
  46. eegFullHour=$(grep -E '^<StartRecordingTime>' "$2" | sed -E 's_.*>(.*)<.*_\1_')
  47.  
  48. if [ $eegDate = "" -o $eegFullHour = "" ]
  49. then
  50.     echo "Eeg start not found, bye"
  51. fi
  52.  
  53. eegS=$(echo $eegDate $eegFullHour)
  54. eegStart=$(date --date "$eegS" +%s.%N)
  55. hz=$(grep -E '^<SamplingRate>' $2 | grep -oE '[0-9]+')
  56.  
  57. duplicates=$(grep -oE '^[^ ]+' timetable.log | sort | uniq -d)
  58. # TODO check if not empty
  59.  
  60. wavStart=$(grep -E '^beep' $1 | grep -oE '[0-9.]+$')
  61. #TODO check if eeg/wav start is empty
  62.  
  63. ticks=$(grep -E '^<tick>' $2)
  64. tickCount=$(echo "$ticks" | wc -l)
  65. echo "ticks = $tickCount"
  66. eegDuration=$(echo "$tickCount / $hz" | bc -l)
  67. eegEnd=$(echo "$eegStart + $eegDuration" | bc)
  68.  
  69. wavDuration=$(sox $3 -n stat 2>&1 | grep '^Length' | sed -E 's_.*[[:space:]]([.0-9]+$)_\1_')
  70. wavEnd=$(echo "$wavStart + $wavDuration" | bc)
  71.  
  72. echo "[file] [start] [end] [duration]"
  73. echo "eeg $eegStart $eegEnd $eegDuration"
  74. echo "wav $wavStart $wavEnd $wavDuration"
  75.  
  76. st=$(cat $1)
  77. IFS=$'\n'
  78. for x in $st; do
  79.     name=$(echo $x | grep -oE '^[^ ]+')
  80.  
  81.     # in case someone decides to put multiple spaces
  82.     durationExpr=$(echo $x | sed -E 's_^.*[[:space:]]+([0-9.]+)[[:space:]]([0-9.]+)$_\2-\1_')
  83.  
  84.     # in unix time
  85.     uStart=$(echo $durationExpr | cut -d'-' -f2)
  86.     uEnd=$(echo $durationExpr | cut -d'-' -f1)
  87.     duration=$(echo $durationExpr | bc | sed -E 's_^[.]_0._')
  88.  
  89.     #echo "Parsed $name $uStart $uEnd $duration"
  90.  
  91.     fail=$(echo "$duration < 0.2" | bc)
  92.     if [ $fail -eq "1" ]
  93.     then
  94.         echo "Duration for $name is too short ($duration), you fucking PoS"
  95.     fi
  96.  
  97.     audioStart=$(echo "$uStart-$wavStart" | bc)
  98. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top