From: Dan White Date: Sat, 7 Dec 2013 20:16:17 +0000 (-0600) Subject: timeSampler: consistent sample times, better sound playing X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=8dc02b541314aa5b8f3c2ac42cffcc8f09d5a2af;p=pubbin.git timeSampler: consistent sample times, better sound playing --- diff --git a/timeSampler b/timeSampler index 1fa7e0d..4777c4a 100755 --- a/timeSampler +++ b/timeSampler @@ -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