Skip to content

Instantly share code, notes, and snippets.

@rxw1
Created December 23, 2013 04:52
Show Gist options
  • Save rxw1/8091778 to your computer and use it in GitHub Desktop.
Save rxw1/8091778 to your computer and use it in GitHub Desktop.
Fun with frequencies
#!/usr/bin/env zsh
# Mon Dec 23 05:48:33 CET 2013
# 2013 (c) [email protected]
# plays frequencies
f=${1:=440}
pids=()
freq() {
case $1 in
+*|-*) f=$(($f$1)) ;;
*) f=$1 ;;
esac
[[ $f -lt 0 ]] && return
[[ ! -z $pid ]] && kill $pid
nohup play -n synth sin $f >/dev/null &
pid=$!
}
freq $f
while true; do
printf "% 7d\r" $f;
read -sk 1 key
case $key in
q) break ;;
-) freq -1 ;;
+|=) freq +1 ;;
J) freq -10 ;;
K) freq +10 ;;
j) freq -100 ;;
k) freq +100 ;;
h) freq -1000 ;;
l) freq +1000 ;;
f) freq $((($f/10**$(($#f-1)))*10**$(($#f-1)))) ;; # floor to somewhere close
c) freq 440 ;;
t) freq 13333 ;;
r) freq $[${RANDOM}%15000] ;;
[0-9]) printf "\t%7d" $key; freq $key$(read -Er); echo -en "\r" ;;
s) pids+=$pid; unset pid; echo "<< $f" ;; # save freq
esac
done
kill $pid
for i in $pids; do kill $i >/dev/null; done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment