timeSampler: consistent sample times, better sound playing
authorDan White <dan@whiteaudio.com>
Sat, 7 Dec 2013 20:16:17 +0000 (14:16 -0600)
committerDan White <dan@whiteaudio.com>
Sat, 7 Dec 2013 20:16:17 +0000 (14:16 -0600)
timeSampler

index 1fa7e0dc9a76a3a275f614ad6b6f315a41c603cd..4777c4ad200a1ccb3e16c1eb90a520b2a42c95e0 100755 (executable)
@@ -8,9 +8,10 @@
 
 # idea from: http://wiki.43folders.com/index.php/Time_sampling
 
-BEEP="beep -f707 -n -f500"
+#BEEP="beep -f707 -n -f500"
 #BEEP="beep -f707 -n -f500 -n -f707"
 #BEEP="dcop knotify default notify notify Me notext KDE_Vox_Ahem.ogg nofile 1 0"
+BEEP="aplay /usr/share/sounds/pop.wav"
 MINUTES=6 #to give 10/hour
 #MAXJOBS=$((1*60/$MINUTES))
 #MAXJOBS=8
@@ -52,8 +53,23 @@ function sampleTask {
 }
 
 
+
+# calculate the minutes to the next $MINUTES slot from top-of-hour
+function nexttime {
+    #remove leading zero to ensure we stay in base-10
+    nowmin=$(date '+%M' | sed 's/^0//')
+    echo $(( $MINUTES - ($nowmin % $MINUTES) ))
+}
+
+
+
+
+thispid=$$
 while true; do
-    [[ $(lastActivity) != "null" ]] && $BEEP && sleep 0.8
+    if [[ $(lastActivity) != "null" ]]; then
+        $BEEP > /dev/null 2>&1
+        sleep 0.8
+    fi
     (sampleTask) &
     pid=$!
 
@@ -73,6 +89,11 @@ while true; do
         fi
     done
 
-    sleep $(($MINUTES*60 - 1))
+    #send a continue signal to myself in the future
+    echo "kill -CONT $thispid" | at now + $(nexttime) minutes > /dev/null 2>&1
+    #stop myself until continued
+    kill -SIGSTOP $thispid
+
+    #sleep $(($MINUTES*60 - 1))
 done