scripts/beep: unify scripts

This commit is contained in:
Michele Guerini Rocco 2022-02-14 13:00:26 +01:00
parent 9381733ab1
commit e0c8082122
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
3 changed files with 23 additions and 30 deletions

23
scripts/beep Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
n=3
case "$5" in
LOW) n=1 ;;
NORMAL) n=3 ;;
CRITICAL) n=5;;
esac
lock=/tmp/.beep-lock
test -f $lock && exit 1
touch $lock
python -c "
import sys, numpy as np
t = np.arange(0, 0.25, 1/48000)
for i in range($n):
tone = np.random.choice([0,3,5,6,7,10,12])
note = 0.2 * np.sin(np.pi * 650 * 2**(tone/12) * t)
sys.stdout.buffer.write(np.int32(2**31 * note).tobytes())
" | aplay -c 1 -f S32_LE -r 48000 -Dbeep
rm -f $lock

View File

@ -1,15 +0,0 @@
#!/bin/sh
lock=/tmp/.beep-lock
test -f $lock && exit 1
touch $lock
head -c 8 /dev/urandom |
hexdump -v -e '/1 "%u\n"' |
awk '{ split("0,3,5,6,7,10,12",a,",");
for (i = 0; i < 1; i+= 0.00012)
printf("%08X\n", 60*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' |
xxd -r -p |
aplay -c 1 -f S32_LE -r 48000 -D plug:default
rm -f $lock

View File

@ -1,15 +0,0 @@
#!/bin/sh
lock=/tmp/.beep-lock
test -f $lock && exit 1
touch $lock
head -c 4 /dev/urandom | \
hexdump -v -e '/1 "%u\n"' |
awk '{ split("0,3,5,6,7,10,12",a,",");
for (i = 0; i < 1; i+= 0.00011)
printf("%08X\n", 40*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' |
xxd -r -p |
aplay -c 2 -f S16_LE -r 48000 -Dvideocard
rm -f $lock